0
好像它在两个地方中断,一个是“>”,二是“/ tmp/testing”。为什么“>”在python2中的subprocess.call中不起作用
Python 2.7.5 (default, Aug 29 2016, 10:12:21)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call(["ls", "-ltr", ">", "/tmp/testing"])
ls: cannot access >: No such file or directory
ls: cannot access /tmp/testing: No such file or directory
2
>>> exit()
我GOOGLE了,并找到其他方式来实现我所需要的。
with.open("/tmp/testing","w") as f:
subprocess.call(["ls", "-ltr"], stdout=f)
想知道为什么第一个脚本不起作用。
因为“>”是shell命令(bash,sh或其他的东西)。/bin/ls本身并不知道有关'>'或'|'的任何信息,等 – Eugene
谢谢@Eugene它是有道理的! –