by Devin Yang
(This article was automatically translated.)

Published - 4 years ago ( Updated - 4 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

linux, python, colab

How to connect to colab from our Server through ssh?

Introduce a bash I wrote to connect to colab vm through ssh. One line of instructions, get colab OpenSSH Server.

python

Macos executes Python and appears certificate verify processing

When I execute python, I get an error note