《Python基础教程里的例子》
#tidy.py
from subprocess import Popen,PIPE
text=open('messy.html').read()
tidy=Popen('tidy',stdin=PIPE,stdout=PIPE,stderr=PIPE)
tidy.stdin.write(text)
tidy.stdin.close()
print tidy.stdout.read()
运行时报错:
root@ubuntu:~/python# python tidy.py
Traceback (most recent call last):
File "tidy.py", line 4, in <module>
tidy=Popen('tidy',stdin=PIPE,stdout=PIPE,stderr=PIPE)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
解决方法:
tidy=Popen('tidy',stdin=PIPE,stdout=PIPE,stderr=PIPE,shell=True)
在参数中添加了shell=True
。