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


Emoji, MacOS

⌘+control+blank (Emoji on Mac)

⌘+control+blank (Emoji on Mac)

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...

linux

Generate ssh key pair without password query

Sometimes it is necessary to generate an ssh key pair for automatic configuration. There is no password query in the command line, and an ssh key pair is generated.