我用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内部或外部调用它有什么好处.
我有一个文件,其中包含我想用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)