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


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.

docker

Install Docker and docker-compose with Raspberry Pi

This article briefly introduces how we install docker and docker-compose on Raspberry Pi.

ssl,certbot

Raiders docker version Let's Encrypt certificate application

This article mainly shares how I use Docker to apply for a Let's Encrypt certificate. Let's Encrypt has quite a variety of ACME Clients, I will use the official push Certbot (ACME Client) for illustration. And use docker to execute ACME Client.