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


About TTFB

TTFB (Time To First Byte): The browser is waiting for the first byte of the response. TTFB stands for time to first byte. This time includes 1 round trip delay and the time for the server to prepare a response.

Ubuntu

Suite of ps commands on Ubuntu

Record how to install ps manually if the system is not installed

docker laravel

Chatting about D-Laravel's console commands

D-Laravel's console command allows us to quickly understand what he executes. How is it executed if docker-compose is used? Let's see.