I am trying to run a bash while loop inside a Python3.6 script. What I have tried so far is:
subprocess.run(args=['while [ <condition> ]; do <command> done;'])
I get the following error:
FileNotFoundError: [Errno 2] No such file or directory
Is there a way to run such a while loop inside Python?
shell=Truekeyword argument. As is, you are trying to execute a binary with the name of the passed in string`. And note that I have never seen any need for this.whileis no program, it is a bash builtin command. Trybash -c "while ..."['/bin/bash', '-c', ' .. your code ..']. That way you can control stdout and stderr if you need.