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


Are you still afraid of losing the idiom Solitaire? Let's try D-Laravel's Facebook bot.

My FaceBook Bot, if you are interested, you can try it out. If you are not sure whether the website can be opened and used directly, you can ask the robot "the idiom of the sea", or ask how many strokes the "building" is, or you can ask him to tell a story, for example: "Nine Bulls and One Feather Story". Currently built-in 160,000 Chinese characters and 3,795 idioms.

CCC IM supports various social platforms OAuth authentication login and guest message

CCC IM supports multiple social platforms to log in, such as Google, Facebook, Twitter, Line, Github , and added a guest message function, you can leave a message without logging in, and you can also create a chat channel.

raspberry,wifi

Is Raspberry Pi connected to a mobile power supply and connected to an iPhone a laptop?

Is a Raspberry connected to a power bank and an iPhone considered a laptop? :p