0

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?

2 Answers 2

1

Evidently, os.system runs 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.

os.system('bash -c "bash <(curl -s http://mysite.com/myscript.sh) World"')
Sign up to request clarification or add additional context in comments.

3 Comments

That almost works, except it doesn't seem to pick up the 'World' parameter.
It works if I leave out the double quotes: os.system('bash -c $(curl -s mysite.com/myscript.sh) World')
@Siou Apparently there is some odd interpretation of arguments going on. I've updated and tested this.
0

There is a libcurl for python so you don't have to go the way around to command line behaviour. Here's the function list that should really do it - have never run remote scripts myself though. If you need installing the python binding, the instructions are here.

import curl

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.