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


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..:)

php

My assembled car LaNativeRoute

Although I like Laravel very much, Laravel has many great features, such as Eloquent ORM, Model, and Blade temple, which I like very much. But seriously, he's really fat, and it's kind of slow to start, so I'm just trying to do it the way I want Extract the functions I want, and assemble this self-made frame micro-frame, which is close to Plain PHP. I think anyone who understands PHP can get started.

laravel

Introduced by @dump, new features in Laravel 5.6.8

In the directive of Laravel 5.6, there is a new function called @dump Let's see how cool he is.