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


Record me compiling siege on macOS

Siege is an http load testing and benchmarking tool. Used to stress test the code. Siege supports basic authentication, cookies, HTTP, HTTPS and FTP protocols. It allows users to access web servers by simulating concurrent connections etc.

jQuery

Uncaught TypeError: Cannot read property 'msie' of undefined error message (jQuery)

Uncaught TypeError: Cannot read property 'msie' of undefined The reason for this message

Synology,cli

Change the password of my Synology NAS via the command line

Adjust password by command line synouser --setpw admin <yourpassword>