现在我有一个测试file.dat,我运行hexdump并将输出放入hexdump.dat文件中。在subprocess.Popen命令中使用变量
subprocess.Popen(['hexdump file.dat > hexdump.dat' ], shell=True)
作为一个方面说明,我所看到的建议,不使用shell=True
但我基本上得到错误OSError: [Errno 2] No such file or directory
。
所以,我想能够传递一个变量或一个数组,文件,而不是硬编码的“file.dat”。 “文件”可以是用户输入或从前面的子流程部分生成的数组/列表。
我已经尝试了用户输入的情况下:
from subprocess import Popen, PIPE, STDOUT
files = raw_input('File Name: ')
p = subprocess.Popen(['hexdump files > hexdump.dat' ], stdout=PIPE, stderr=STDOUT)
out,err = p.communicate(input=files)
而且具有:
p = subprocess.Popen(['hexdump', inputs, ' > hexdump.dat' ], stdout=PIPE, stderr=STDOUT)
感谢您的帮助,我知道我没有理解正确这里所需要的结构,使一些“handholdy “答案将不胜感激。
你试过的是什么问题? – user312016
Error Output:Traceback(last recent call last): 文件“scratchpadDecoder.py”,第47行,在 subprocess.Popen(['hexdump file.dat> hexdump.dat']) 文件“/ dsw/python -2.7.1/lib/python2.7/subprocess.py“,第672行,在__init__中 errread,errwrite) 文件”/dsw/python-2.7.1/lib/python2.7/subprocess.py“,行1202,在_execute_child raise child_exception –
stackofpancakes