我试图通过python子进程运行执行此命令。我当前的目录包含文件夹splitta103,它包含sbd.py文件和model_nb文件夹。
python splitta103 / sbd.py -m splitta103 / model_nb info.txt
这是我的python程序
file = 'info.txt'
print(subprocess.check_output(['splitta103','/','sbd.py','-m','splitta103','/','model_nb',file]))
这是错误
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-27-743654b05145> in <module>()
12 text_file = 'info.txt'
13
---> 14 print(subprocess.check_output(['splitta103','/','sbd.py','-m','splitta103','/','model_nb','info.txt']))
15 #print(subprocess.check_output(['sbd.py','-m','model_nb','info.txt']))
16
/home/joe/anaconda2/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
210 if 'stdout' in kwargs:
211 raise ValueError('stdout argument not allowed, it will be overridden.')
--> 212 process = Popen(stdout=PIPE, *popenargs, **kwargs)
213 output, unused_err = process.communicate()
214 retcode = process.poll()
/home/joe/anaconda2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
388 p2cread, p2cwrite,
389 c2pread, c2pwrite,
--> 390 errread, errwrite)
391 except Exception:
392 # Preserve original exception in case os.close raises.
/home/joe/anaconda2/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
1023 raise
1024 child_exception = pickle.loads(data)
-> 1025 raise child_exception
1026
1027
OSError: [Errno 2] No such file or directory
答案 0 :(得分:1)
这:print(subprocess.check_output(['splitta103','/','sbd.py','-m','splitta103','/','model_nb','info.txt']))
在命令行上看起来像splitta103 / sbd.py -m splitta103 / model_nb info.txt
。
这在命令行上:python splitta103/sbd.py -m splitta103/model_nb info.txt
可以用以下方式制作:['python', 'splitta103/sbd.py', '-m', 'splitta103/model_nb', 'info.txt']