by Devin Yang
(This article was automatically translated.)

Published - 7 years ago ( Updated - 7 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

Install docker-compose on ubuntu

Briefly introduce how I installed docker-compose on ubuntu. Quite easy.

ffmpeg

ffmpeg's batch conversion skills webm to mp3

This article introduces how I do multi-file format conversion in one directory. When you learn it, you can definitely conjure up new tricks.

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.