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


Synology,NAS

Remove IP of Synology NAS Block via command line

In some cases, your IP may be locked by the Synology NAS, for example, the email host is installed on the Synology NAS, and the email password is incorrectly set. Or Synology did not correctly set the forward header of the real IP on the internal network. No matter what the reason is, we want to remove the locked IP through the command line.

dlaravel

Use docker in docker to build a D-Laravel test environment.

D-Laravel is an extremely easy-to-use and extremely flexible Laravel development environment. As long as you are a Mac user, even if you don’t know Docker, you can use it to create Laravel projects and develop them. Due to the newly added .env function When it comes to functions, those who are in a hurry push, but there is no complete test, and a bunch of new bugs are created. Therefore, this time, a new dlaravel_test, a bash testing tool, is added to run the test through docker in docker. Make sure that every release of D-Laravel can be a stable version.

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.