所以在Python中,我正在尝试创建一个unix屏幕并让它执行一个命令,但它不起作用。
屏幕不是事件创建的,如果我运行screen -ls
这是代码:
def run_screen_with_command(command):
screens = []
command = ['screen', '-d', '-m', '-S', 'myscreen', 'bash', '-c', "'{}'".format(command)]
process = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
process.wait()
print(process.stderr, process.stdout.read())
#returncode = process.wait()
print ' '.join(command)
return process
run_screen_with_command('sleep 10')
答案 0 :(得分:2)
您不需要引用bash
-c
的参数,因为shell不会执行它。
command = ['screen', '-d', '-m', '-S', 'myscreen', 'bash', '-c', command]