如何从python子进程执行netcat命令?



我需要通过python脚本执行Altair Accelerator,以前称为NetworkComputer (NC)。shell命令是:nc run -q vnc01 run -C TEST -wl -I -r+ CORES/32 -r+ RAM/150000 -- /bin/tcsh我试过这个代码:

with open('test.txt', 'w') as f:
process = subprocess.Popen(['nc run',' -q vnc01  run -C TEST -wl -I -r+ CORES/32 -r+ RAM/150000 -- /bin/tcsh'], stdout=f)

返回以下错误:

Traceback (most recent call last):   File "nc.py", line 11, in <module>
process = subprocess.Popen(['nc run',' -q vnc01 run -C TEST -wl -I -r+ CORES/32 -r+ RAM/150000 -- /bin/tcsh'], stdout=f)   File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)   File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception OSError: [Errno 2] No such file or directory Exit 1

您需要正确分割命令参数:

process = subprocess.Popen([
'nc',
'run', '-q', 'vnc01',
'run', '-C', 'TEST',
'-wl', '-I',
'-r+', 'CORES/32',
'-r+', 'RAM/150000',
'--',
'/bin/tcsh'
], stdout=f)

最新更新