Python的庆典管 [英] Python bash pipe
问题描述
我要管一个Python脚本的输出到bash脚本。我所做的,到目前为止是我试图用 os.popen()
, sys.subprocess()
,并试图给管道的例子
I want to pipe a python script's output to a bash script. What i did so far was i tried to use os.popen()
, sys.subprocess()
, and tried to give a pipe for an example
os.popen('echo "P 1 1 591336 4927369 1 321 " | v.in.ascii -zn out=abcx format=standard --overwrite')
但这并没有工作,值591336
和4927369
是变量,来作为python脚本的输出。但我这样做,或通过重复echo命令和管道手动更改数值时,它的工作原理(在bash)。
but this didn't work, the values "591336"
and "4927369"
are the variables which comes as the output of the python script. but when I do this or change the values manually by repeating the echo command and the pipe, it works (in bash).
v.in.ascii -zn out=abcx format=standard --overwrite
bash命令上面部分是草GIS
the above part of the bash command is a part of Grass GIS
谁能帮我!
推荐答案
您可以只用打印
输出到标准输出和管道Python的过程中下道工序,如
You can just use print
to output to stdout and pipe the Python process to the next process, e.g.
python myprogram.py | ...
其中, myprogram.py
看起来像:
for x in something:
print dosomething(x)
这篇关于Python的庆典管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!