by Devin Yang
(This article was automatically translated.)

Published - 6 years ago ( Updated - 6 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


EBS Volume, mount, ubuntu

Create a ready-to-use Amazon EBS volume

This article completely records the complete process of my formatting and mounting the EBS volume. The text has complete steps and reference links to the original text.

php

Talking about PSRs

The full name of PSR is called "PHP Standards Recommendations" (PHP Standards Recommendations). A proposed specification developed by FIG (PHP Framework Interoperability Group), This group was initiated by some framework developers in php|tek in 2009, from the first 5 to more than 20 now. There are many numbers in the "PHP Standard Recommendations", each number represents a different specification.

big5

PHP version of big5 to utf8 program

Do you have a large number of big5-encoded php, js or html pages that need to be transcoded? Here is my original php transcoding method, which uses PHP programs to transcode files. The transcoding of database big5 via latin1 is more complicated, so this article will not discuss it. The most important thing before transcoding is to control the version of your target folder, so that after transcoding, you can compare whether there is a normal transcoding success.  Or when there is a problem, you can also perform the restoration method.