我对python很陌生。目标是使用子进程解析&从shell中检索打印输出来执行shell命令。执行错误如下面的示例输出msg中所示。还示出了下面是示例代码段在Python中转义转义序列
代码段:
testStr = "cat tst.txt | grep Location | sed -e '/.*Location: //g' "
print "testStr = "+testStr
testStrOut = subprocess.Popen([testStr],shell=True,stdout=subprocess.PIPE).communicate()[0]
输出:
testStr = cat tst.txt | grep Location | sed -e '/.*Location: //g'
cat: tst.txt: No such file or directory
sed: -e expression #1, char 15: unknown command: `/'
有一种解决方法,或者可以使用的功能?
感谢您的帮助 感谢
给予子过程文件“tst.txt”的完整路径。 – MBarsi 2011-05-26 09:45:28