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


docker

Command to remove all docker containers and docker images

Sometimes I tried a bunch of containers or images in my own environment, how to remove all images and containers in the system? These instructions are provided for your reference..

linux,termux

how to play mp4 or webm in android phone background

I have some audio files downloaded from Youtube that I want to play in the background, do I know how to do it?

linux,system

Detect whether selinux is enabled in the system

Detect whether selinux is enabled in the system