Home  >  Article  >  Backend Development  >  python capture shell script output example

python capture shell script output example

高洛峰
高洛峰Original
2017-02-06 13:32:531324browse

import subprocess
output =Popen(["mycmd","myarg"], stdout=PIPE).communicate()[0]


import subprocess
p = subprocess .Popen(['ls','-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out

# work on Unix/Linux only

import commands
print commands.getstatusoutput('wc -l file')[1]

The above is what the editor has done for you The entire content of the examples of python capturing the output results of shell scripts has been brought. I hope everyone will support the PHP Chinese website~

For more articles related to the examples of python capturing the output results of shell scripts, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn