the required output ==> myfile.tar.gz ==> myfile.tar ==> myfile.bin

我运行的命令...

subprocess.call(['tar', '-zcvf', '/path/to/desitnation/myfile.tar.gz', "./path/to/file/myfile.bin"]

the output I get is

myfile.tar.gz==>myfile.tar==>./path/to/file/myfile.bin

python
linux
Exorcismus
Exorcismus
发布于 2022-08-29
1 个回答
larsks
larsks
发布于 2022-08-29
已采纳
0 人赞同

tar有一个-C--directory)选项,使它在开始处理文件之前改变目录。

subprocess.call(['tar',
  '-C', '/path/to/file/',
  '-zcvf',
  '/path/to/destination/myfile.tar.gz', "myfile.bin"])

See the tar man page详情请见下文。

你可以用cwd的参数来完成同样的事情,即subprocess.call

subprocess.call(['tar',