我有一个带有原始输入命令的python脚本,但是我想在用户输入raw_input部分后在后台运行它。我遇到的问题是,如果我尝试使用&在后台运行脚本,原始输入将作为linux命令弹出,而python脚本无法识别它。
有小费吗?
您可以fork
用来创建子进程,然后退出父进程。
#!/usr/bin/env python
import os
import sys
import time
_ = raw_input('Enter the the secret code: ')
if os.fork(): # returns 0 in the child, pid of the child in the parent
sys.exit()
time.sleep(2)
print('All good things must come to an end')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句