I'm trying to run a bash-command in python where the bash-command saves data to a file rather than displaying it. An example of such command is
$ echo 'foo' > bar.txt
currently my code looks like the following
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
process.communicate()
As I run the python-code no bar.txt is generated. Any idea on how to save the data from the bash-script? The data should not be displayed only saved.
>and shell-builtins likeecho, requirebash. So addshell=Trueto yourPopen.stdoutargument if you redirect the commands output with>.