【发布时间】:2017-07-10 15:15:30
【问题描述】:
我在 python 中执行 shell 命令时遇到问题。这是导致错误的代码的某些部分:
p = subprocess.Popen(["cat input.txt |apertium -d. kaz-morph|\
sed -e 's/\$\W*\^/$\n^/g'| cut -f2 -d'/'|cut -f1 -d '<'|\
awk '{print tolower($0)}'|sort -u>output.txt"], shell=True, stdout=f1)
仍然收到错误:未终止的“s”命令。
希望你能帮助我,因为我解决了 10 天 :(
附言对不起我的英语
【问题讨论】:
-
另外,用
shell=True,只要一个字符串就可以了,不需要使用字符串列表 -
将该脚本放入单独的文件中可能会更干净,例如
~/morph-and-sort.sh并执行chmod +x ~/morph-and-sort.sh并将 python 更改为Popen(["~/morph-and-sort.sh"], shell=True,stdout=f1)