running a command line containing Pipes and displaying result to STDOUT

前端 未结 6 964
不思量自难忘°
不思量自难忘° 2020-12-01 06:20

How would one call a shell command from Python which contains a pipe and capture the output?

Suppose the command was something like:

cat file.log |          


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 06:52

    Another way similar to Popen would be:

    command=r"""cat file.log | tail -1 """
    output=subprocess.check_output(command, shell=True)
    

提交回复
热议问题