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


docker

Where is the volume location of Docker?

we can use docker volume ls List all dossiers. When using inspect on OSx to view, as a result, we can't find the Mountpoint directory when we get to the Mac?

python

Simple test python-thread function and parameters

Record, how to use thread to perform functions

synology,log center,rsyslog,syslog

Use the Synology Log Center to centrally view the logs of the host

This article introduces how I use the Synology Log Center to record all the logs of my home host. In Synolog's log center, we can search through its UI. In this way, we can centrally view our logs, such as the scheduled execution status of Linux hosts. It can also send messages to the log center through commands, and we can check the daily backup tasks of the Linux host at any time, whether the backup is successful or failed, etc.