Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将参数传递给已通过管道输送到Python进程的卷曲脚本?_Python_Shell_Curl - Fatal编程技术网

如何将参数传递给已通过管道输送到Python进程的卷曲脚本?

如何将参数传递给已通过管道输送到Python进程的卷曲脚本?,python,shell,curl,Python,Shell,Curl,我有一个Github gist上的Python脚本,我可以使用它从我的终端进行卷曲 curl -s https://gist.githubusercontent.com/.../script.py 该脚本有一个执行的主函数,我可以将curl语句的输出通过管道传输到Python,Python执行该脚本 curl -s https://gist.githubusercontent.com/.../script.py | python 上面的语句可以工作,但我想为脚本提供一些命令行参数,而不必将其

我有一个Github gist上的Python脚本,我可以使用它从我的终端进行卷曲

curl -s https://gist.githubusercontent.com/.../script.py
该脚本有一个执行的主函数,我可以将curl语句的输出通过管道传输到Python,Python执行该脚本

curl -s https://gist.githubusercontent.com/.../script.py | python
上面的语句可以工作,但我想为脚本提供一些命令行参数,而不必将其下载到文件中。我面临的问题是Python命令将其后面的任何文本视为要执行的内容,而不是管道文件的参数,所以

curl -s https://gist.githubusercontent.com/.../script.py | python arg1 arg2
不起作用,也不起作用

curl -s https://gist.githubusercontent.com/.../script.py arg1 arg2 | python

如何将这两个参数作为标准输入或脚本可以读取的命令行选项传入文件?

您可以将脚本保存在本地,然后执行它

curl -o some_filename.py some_link
python some_filename.py arg1 arg2
您还可以使用以下命令将卷曲输出保存到文件:

curl some_link > some_file.py
从CLI帮助:

-
:从stdin读取的程序(默认;如果是tty,则为交互模式)

所以你想要的是:

curl -s https://gist.githubusercontent.com/.../script.py | python - arg1 arg2
但是请注意,
-
也将出现在
sys.argv
中(代替脚本的文件名)

$ echo "import sys; print sys.argv" | python - arg1 arg2
['-', 'arg1', 'arg2']