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


Polymer,Webcomponents

Just to be different, CCC IM beta adopts Laravel+Polymer 2.0 development version and is going online

Using WSS encryption, the community chat program developed using Laravel framework + Polymer 2.0 is currently under development. The goal is to create a chat room + IM suitable for developers to discuss. Currently, you can create chat channels and invite link functions. In the future, you will consider adding One on One one-to-one video calls and electronic whiteboard functions. If you want to know more about Polymer or CCC IM, click here to have a look.

iOS,Android

2020 Android vs iPhone Voice Assistant Showdown

Recently, before Apple's iPhone 12 went on sale, I rushed to Sony's xperia 5 II, which was first launched on 10/07. As an Apple user for many years, after the battery door incident, I don't really like Apple's style of asking for money. For a developer, I always hope that he can support PWA, but he has not done it for several years. Guess I also know that for the profit of their store, they just don't support it... Then I will switch to Android...

Synology,NAS

Remove IP of Synology NAS Block via command line

In some cases, your IP may be locked by the Synology NAS, for example, the email host is installed on the Synology NAS, and the email password is incorrectly set. Or Synology did not correctly set the forward header of the real IP on the internal network. No matter what the reason is, we want to remove the locked IP through the command line.