问题描述
我需要实现一个SVN预提交钩子,该钩子执行本身存储在SVN中的脚本.
I need to implement an SVN pre-commit hook which executes a script that itself is stored in SVN.
我可以使用svn cat
命令将该脚本通过管道传递到Python解释器,如下所示:
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
但是,my_script.py
本身要求将数据通过管道传输到STDIN.
However, my_script.py
itself requires data to be piped on STDIN.
该数据未存储在文件中;它存储在网络上.我希望不必将数据下载到一个临时文件,因为通常我可以将其通过管道传输到Python程序:
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.
推荐答案
我想出了如何在不创建任何临时文件的情况下执行此操作的方法,但并非严格使用管道".
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
我在Bash中使用了匿名文件描述符"构造,可以用它代替任何文件路径.
I used the "anonymous file descriptor" construct in Bash, which can be used in place of any file path.
例如python my_script.py
相当于python <(cat my_script.py)
这篇关于将STDIN管道传输到本身通过管道传递给Python解释器的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!