Reputation: 29
Are there any differences between the following 2 lines:
subprocess.Popen(command + '> output.txt', shell=True)
subprocess.Popen(command +' &> output.txt', shell=True)
As the popen already triggers the command to run in the background, should I use &
? Does use of &
ensure that the command runs even if the python script ends executing?
Please let me know the difference between the 2 lines and also suggest which of the 2 is better. Thanks.
Upvotes: 2
Views: 201
Reputation: 2159
&>
specifies that standard error has to be redirected to the same destination that standard output is directed. Which means both the output log of the command and error log will also be written in the output.txt file.
using >
alone makes only standard output being copies to the output.txt file and the standard error can be written using command 2> error.txt
Upvotes: 3