I will need python for my future work, so I decided to make a lot of python scripts.
# coding: utf-8 """how to use exec_shell.An xml file containing the py command Parse the command tag in the xml file that contains the command A script that executes a parsed command """ #Module import from subprocess import Popen,PIPE import xml.etree.ElementTree as et import sys #Variable definition cmdfile=sys.argv tree=et.parse(cmdfile) cmd=tree.find(".//code").text #Function definition def main(cmd): p=Popen(cmd,shell=True,stdout=PIPE,stderr=PIPE) result=p.communicate() return result #Main processing if __name__ == '__main__': result=main(cmd) print('Standard output result: ' + str(result)) print('Standard error output result: ' + str(result))
Right now, it seems normal to use the subprocess module instead of using "os.commands". It seems that subprocess.call () can only handle the return value of the command, so I will use Popen.
In this script, the standard output result is stored in result , and the standard error output result is stored in result .
The command to be executed, including redirection, is put in the cmd variable. This means that if the command changes, you only need to change the cmd variable.
We plan to add a little more error handling.