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


vpn,cli,macos

How do I dial a VPN from the command line on MacOS

I myself will need to use MacOS to dial VPN in the command line. Here I provide my alias and setting method

linux

Remove the Linux Kernel that is not used by the old version on Ubuntu

This page describes how I removed the old version of Linux Kernel taking up space on ubuntu.

sublime

Hotkey settings for sublime3 macros

1. Re-tools=>Record Marco to record. 2. Save the recorded macro as a file. tools=>Save Marco... 3. Set hotkeys and execute macros.