簡體   English   中英

將 python 腳本 output 存儲到 linux 中的變量並運行 wget 命令

[英]Storing a python script output to a variable in linux and run a wget command

所以我制作了一個 python 腳本來檢索 url 鏈接並將其作為 output 返回。為了簡單起見,python 腳本的內容將只是:

print("https://www.testweb.com/file=ejfeafjaiaefjaof")

例如,如果我在終端中執行 python 腳本:

python retrieve_url.py

它輸出:

https://www.testweb.com/file=ejfeafjaiaefjaof

所以我想利用 linux 中的“wget”命令和我的 python 腳本返回的 url,這樣我就可以做類似的事情:

wget https://www.testweb.com/file=ejfeafjaiaefjaof

但是,是否可以將 python output url 存儲在一個變量中,並在一個 go 中執行 linux 腳本? 我在想創建一個可執行腳本, run.sh

python retrieve_url.py
wget **some argument to store the python output**

並使用./run.sh。

像這樣保存 python 腳本的 output

test=$(python test.py)

echo $test
"https://www.testweb.com/file=ejfeafjaiaefjaof"

wget只需要使用-i-標志從標准輸入讀取 URL:

python retrieve_url.py | wget -i-

Output:

--2021-01-14 16:15:17--  https://example.org/
Resolving example.org (example.org)... 93.184.216.34
Connecting to example.org (example.org)|93.184.216.34|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1256 (1,2K) [text/html]
Saving to: ‘index.html’

index.html                                        100%[============================================================================================================>]   1,23K  --.-KB/s    in 0s

2021-01-14 16:15:17 (20,0 MB/s) - ‘index.html’ saved [1256/1256]

FINISHED --2021-01-14 16:15:17--
Total wall clock time: 0,6s
Downloaded: 1 files, 1,2K in 0s (20,0 MB/s)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM