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


ansible,bash

My first ansible, automated database transfer

In this article, I use Docker on MacOS to share my experience in using Ansible. You can adjust it to your desired Ansible environment according to this directory structure, or learn Ansible. The situation is like this, I hope that in my test environment, I can see articles that are the closest to the official machine, but I don't want to use the test machine program to directly connect to the database of the official machine. My manual method is to export the db of the official machine, copy it to the test machine and then import it. Although there are not a few steps, it seems to be a bit annoying to do, and manual operation is easy to make mistakes. This reminds me of Ansible. I've heard of it but haven't tried it, so why not give it a try.

mysql

How to change the password authentication method of mysql

After mysql 8.0.4, a new authentication plug-in caching_sha2_password is used by default. How can we tell if our system does not support this plug-in?

web-hosting,laravel

Zhibang installs Laravel 5.4 experience sharing

Install Laravel 5.4 on Zhibang's Linux 7.0 platform, and successfully execute the case sharing, Because it was originally an old version of PHP, it can be transferred to the new version for free for the first time, So please ask them to open a test php 7.0 environment for us to test, after small adjustments, Laravel's environment can indeed be executed on Accton's managed host. This article introduces how I successfully implemented Laravel's website process in Zhibang.