by Devin Yang
(This article was automatically translated.)

Published - 3 years ago ( Updated - 3 years ago )

I use Python to execute the template of system commands

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE, STDOUT

command='uname -a'. split()

proc=Popen(command,bufsize=0, stdout=PIPE,stderr=PIPE, universal_newlines=True);
output, error = proc. communicate()
exit_code=proc.poll()

if (exit_code==0):
  print(output)
else:
  print(error)

Tags: python

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


python

Simple test python-thread function and parameters

Record, how to use thread to perform functions

python

Macos executes Python and appears certificate verify processing

When I execute python, I get an error note

python

The python version of the tirm command

Record how to use python's tirm command