Python Language Calling External Commands


The simplest use case is using the function. It accepts a list as the first argument. The first item in the list should be the external application you want to call. The other items in the list are arguments that will be passed to that application.[r'C:\path\to\app.exe', 'arg1', '--flag', 'arg'])

For shell commands, set shell=True and provide the command as a string instead of a list.'echo "Hello, world"', shell=True)

Note that the two command above return only the exit status of the subprocess. Moreover, pay attention when using shell=True since it provides security issues (see here).

If you want to be able to get the standard output of the subprocess, then substitute the with subprocess.check_output. For more advanced use, refer to this.