Python-如何將字符串傳遞到子進程.Popen(使用stdin參數)?如果我這樣做的話:import subprocessfrom cStringIO import StringIOsubprocess.Popen(['grep','f'],
stdout=subprocess.PIPE,stdin=StringIO('one\ntwo\nthree\nfour\nfive\nsix\n')).communicate()[0]我得到:Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/build/toolchain/mac32/python-2.4.3/lib/python2.4/subprocess.py", line 533, in __init__ (p2cread, p2cwrite,
File "/build/toolchain/mac32/python-2.4.3/lib/python2.4/subprocess.py", line 830, in _get_handles
p2cread = stdin.fileno()AttributeError: 'cStringIO.StringI' object has no attribute 'fileno'顯然,cStringIO.StringIO對象與文件鴨子的作用不夠接近,無法適應子進程。我該怎么處理這件事?
添加回答
舉報
0/150
提交
取消