I have a python script that is running linux command to check if file exist:
>>> p = subprocess.Popen([ 'sudo', 'test', '-f', '/root/some_file', '&&', 'echo', 'True', '||', 'echo', 'False' ])
>>> test: extra argument `&&'
>>> p = subprocess.Popen('sudo test -f /root/some_file && echo True || echo False' ], shell=True)
According to this answer: Python: subprocess call with shell=False not working
When calling Popen with shell=True you should use a string. When calling Popen with shell=False you should use a list.
Using '&&' and '||' will only work if you are using shell=True as they require the shell. This means that you can only get this to work using a string as your command, not a list.
If you are getting your command as a list, then you can just do something like: