我想使用(os.system
...或subprocess
模块)在系统中执行一些命令,并确保shell=False
,所以我尝试了以下操作:
os.system('ssh -R 80:localhost:3000 serveo.net')
和
subprocess.call('ssh -R 80:localhost:3000 serveo.net', shell=True)
它可以工作,但是会挂起,直到过程完成为止,而我所不想要的是,我真的想执行命令并在执行命令时完成程序,所以我尝试了此操作:
subprocess.call('ssh -R 80:localhost:3000 serveo.net', shell=False)
但是,这引发了异常
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/local/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ssh -R 80:localhost:3000 serveo.net': 'ssh -R 80:localhost:3000 serveo.net'
我的问题是,如何在程序关闭时保持命令运行?
/etc/rc.local
文件)。