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' ])
It produces error:
>>> test: extra argument `&&'
If pass the command as a single then it executes successfully:
>>> p = subprocess.Popen('sudo test -f /root/some_file && echo True || echo False' ], shell=True)
>>> True
Why does it fail if pass command as a list?
I have to use both && and || to check if the root's file exist so I can't convert it to the chain of separate commands as suggested here