Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe STDIN to a script that is itself being piped to the Python interpreter?

I need to implement an SVN pre-commit hook which executes a script that itself is stored in SVN.

I can use the svn cat command to pipe that script to the Python interpreter, as follows:

svn cat file://$REPO/trunk/my_script.py | python - --argument1 --argument2

However, my_script.py itself requires data to be piped on STDIN.

That data is not stored in a file; it is stored on the network. I would prefer not to have to download the data to a temporary file, as normally I could pipe it to a Python program:

curl http://example.com/huge_file.txt | python my_script.py

I'm not sure how to combine both of these pipes.

like image 494
kostmo Avatar asked Sep 12 '12 23:09

kostmo


1 Answers

I figured out how to do this without creating any temporary files, but not strictly with "pipes".

curl http://example.com/huge_file.txt | python <(svn cat file://$REPO/trunk/my_script.py) --argument1 --argument2

I used the "anonymous file descriptor" construct in Bash, which can be used in place of any file path.

E.g. python my_script.py would be equivalent to python <(cat my_script.py)

like image 141
kostmo Avatar answered Sep 21 '22 02:09

kostmo