Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.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脚本输出存储到linux中的变量并运行wget命令_Python_Linux_Shell - Fatal编程技术网

将python脚本输出存储到linux中的变量并运行wget命令

将python脚本输出存储到linux中的变量并运行wget命令,python,linux,shell,Python,Linux,Shell,因此,我制作了一个python脚本,用于检索url链接并将其作为输出返回。为了简单起见,python脚本的内容如下: print("https://www.testweb.com/file=ejfeafjaiaefjaof") 例如,如果我在终端中执行python脚本: python retrieve_url.py 它输出: https://www.testweb.com/file=ejfeafjaiaefjaof 因此,我想利用linux中的“wget”命令和pyth

因此,我制作了一个python脚本,用于检索url链接并将其作为输出返回。为了简单起见,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输出url存储在变量中并一次性执行linux脚本?我想创建一个可执行脚本,run.sh

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

只需使用./run.sh.

保存python脚本的输出,如下所示

test=$(python test.py)

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

这样保存python脚本的输出

test=$(python test.py)

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

wget
只需使用
-i-
标志从stdin读取URL:

python retrieve_url.py | wget -i-
输出:

--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)

wget
只需使用
-i-
标志从stdin读取URL:

python retrieve_url.py | wget -i-
输出:

--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)

梅尔,谢谢!如果wget正在检索一个压缩文件,并且我想随后执行一个解压缩过程,那么wget语句后面会是“| unzip-o-”吗?@Maxxx:
wget
需要将下载写入stdout
python retrieve_url.py | wget-i--qO-| tar xvf-
Mayer,谢谢!如果wget正在检索一个压缩文件,并且我想随后执行一个解压缩过程,那么wget语句后面会是“| unzip-o-”吗?@Maxxx:
wget
需要将下载写入stdout<代码>python检索_url.py | wget-i--qO-| tar xvf-