我想將bash命令翻譯成python中的子流程。 bash命令是:試圖將bash語句翻譯爲python中的子流程
cat LogFile.msg.log | grep ABCD | awk'{print $ 14,$ 10,$ 5,$ 7}'| sort -t''-k4 -n -r |頭-10> output.csv
到目前爲止,我已爲子如下:
cat = subprocess.Popen(['cat', 'LogFile.msg.log'],
stdout=subprocess.PIPE,
)
grep = subprocess.Popen(['grep', 'ABCD'],
stdin=cat.stdout,
stdout=subprocess.PIPE,
)
awk = subprocess.Popen(['awk', '{print $14,$10,$5,$7}'],
stdin=grep.stdout,
stdout=subprocess.PIPE,
)
sort = subprocess.Popen(['sort', '-t','' '', '-k4', '-n', '-r'],
stdin=awk.stdout,
stdout=subprocess.PIPE,
)
head = subprocess.Popen(['head', '-10'],
stdin=sort.stdout,
stdout=subprocess.PIPE,
)
out = subprocess.Popen(['>', 'output.csv'],
stdin=head.stdout,
stdout=subprocess.PIPE,
)
end_of_pipe = out.stdout
現在我收到以下錯誤:
Sort: empty tab
Traceback (most recent call last):
File "./latency2", line 39, in <module>
stdout=subprocess.PIPE,
File "/usr/lib64/python2.6/subprocess.py", line 639, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1228, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
我敢肯定,我錯過了一些東西,但不知道是什麼。
你確定你的工作目錄是正確的? – eazar001 2013-04-10 04:57:46