by Devin Yang
(This article was automatically translated.)

Published - 7 years ago ( Updated - 7 years ago )

The most simplified version of the Python system command execution template

#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE, STDOUT
#executed command
command='ls -l'. split()
proc=Popen(command, stdout=PIPE, stderr=PIPE, universal_newlines=True);
output, error = proc. communicate()

#display execution result
if(proc. poll()==0):
     print(output)
else:
     print("{} Error\n".format(error))


 

Tags:

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


sort

How to list the file size of the first layer on the command line?

If you want to create a duf alias, use the command to display the first-level folder and file size?

javascript

Introducing document.designMode

document.designMode, you can control the entire document to become editable. We adjust by "on" and "off". We can do many things through document.execCommand, for example: insertText.