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


dlaravel

[D-Laravel] about chowner.

About D-Laravel's Chowner This article explains the function of chowner in D-Laravel. If you are a Linux user, you may need to do this.

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.

linux, cli

How to use the find command to find files that have been changed within 7 days

If we have changed some files, how to find out through the command line?