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


redis

Redis Key Notes

Redis is an advanced NoSQL key-value data storage, also known as a data structure server. Because it has powerful data types, such as Strings, Hashes, Lists, Sets, Stored Sets, Bitmas, and HyperLogLogs. By default, Redis stores all data in memory, so the reading and writing speed is very fast. He can also save the data permanently on the disk, such as snapshotting and journaling we know.

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.

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.