Assume I have a file at http://mysite.com/myscript.sh that contains:
#!/bin/bash
echo "Hello $1"
From the command line, I can execute my script (without downloading it) using the following command:
bash <(curl -s http://mysite.com/myscript.sh) World
Now, instead of executing the above command from the command line, I want to execute it from a python script. I tried doing the following:
import os
os.system('bash <(curl -s http://mysite.com/myscript.sh) World')
…but I get the following error:
sh: -c: line 0: syntax error near unexpected token `(‘
How do I make this execute correctly in python?
Evidently,
os.systemruns its command through/bin/sh, which usually causes whichever shell it’s linked to to drop to a compatibility mode that doesn’t include the<(...)construction. You can get around it by either storing the result in a temporary file or using another level of shell. Ugly, but it works.