[英]Redirect bash pipe output as python script second argument
我在將管道輸出重定向為python腳本的第二個參數時遇到問題。 基本上,我的代碼將是這樣的:
sort -u inputfile.txt | python myscript.py Firstargument.txt PIPE_OUTPUT_AS_SECOND_ARGUMENT | other_bash_commands
問題顯示為大寫。
由於我對bash和python都缺乏經驗,這也是我的python腳本的樣子:
script, firstargument, mypipeoutput = argv
def myfunction(a, b):
# <insert well written function here using a and b>
firstarg= open(firstargument)
secondarg=open(mypipeoutput)
myfunction(firstarg, secondarg)
除了無法正常工作外,我的撰寫方式似乎也很多余,因此,如果您有其他建議可以使其更加簡單明了,我將很高興聽到它們。
尚不清楚這是否是您要的,但是如果您希望將排序輸出作為腳本的第二個參數給出,那么您需要:
python myscript.py FirstArgument "$(sort -u inputfile.txt)" | ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.