I have the following command that I want to execute in Python and store in a variable:
ls -1 var1 2>/dev/null | grep var2 | grep var3 | head -n 1
But I can't get it to work. I tried using subprocess (both 'call' and 'check_output' as well as 'os.system' and nothing worked.. It always gave me an error or a wrong input, while when I execute this command in the shell it works properly.