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


LineBot adds the function of storytelling

The Line Bot on CCC has added a "storytelling" function, in addition to the original idiom Solitaire, ​​​​​​​​Now I will also randomly tell stories, welcome to add friends..:)

linux,raspberry

Install VNC Server on Raspberry Pi

Checklist introduces how to start VNC Server on Raspberry Pi

How to separate video and audio in Final Cut Pro

use hotkeys Command+Shift+G Video and audio can be separated.