相关疑难解决方法(0)

子进程中'shell = True'的实际含义

我用subprocess模块调用不同的进程.但是,我有一个问题.

在以下代码中:

callProcess = subprocess.Popen(['ls', '-l'], shell=True)
Run Code Online (Sandbox Code Playgroud)

callProcess = subprocess.Popen(['ls', '-l']) # without shell
Run Code Online (Sandbox Code Playgroud)

两者都有效.阅读文档后,我开始知道这shell=True意味着通过shell执行代码.这意味着在缺席的情况下,该过程将直接启动.

那么我应该更喜欢我的情况 - 我需要运行一个进程并获得其输出.从shell内部或外部调用它有什么好处.

python subprocess

236
推荐指数
5
解决办法
14万
查看次数

从文件列表中获取输入的Tar归档

我有一个文件,其中包含我想用tar存档的文件列表.我们称之为mylist.txt

它包含:

file1.txt
file2.txt
...
file10.txt
Run Code Online (Sandbox Code Playgroud)

有没有办法可以发出mylist.txt作为输入的TAR命令?就像是

tar -cvf allfiles.tar -[someoption?] mylist.txt
Run Code Online (Sandbox Code Playgroud)

所以它就像我发出这个命令一样:

tar -cvf allfiles.tar file1.txt file2.txt file10.txt 
Run Code Online (Sandbox Code Playgroud)

unix linux tar archive

146
推荐指数
6
解决办法
13万
查看次数

标签 统计

archive ×1

linux ×1

python ×1

subprocess ×1

tar ×1

unix ×1