Python 2.x在不同的目录中运行命令行命令

时间:2016-03-26 23:37:35

标签: python linux

让我们说我运行的Python脚本存储在~SomeFolder/sample_project

如果我想运行此命令:

import subprocess

command_pushd ='pushd /Users/user/Desktop/test'.split()
subprocess.call(command_pushd)

>>> ~/Desktop/test ~/SomeFolder/sample_project

我希望pushd命令仅引用/Users/user/Desktop/test文件路径。后续命令不起作用并抛出此错误:

command_zip ='zip -r -e -Ptest test.zip ./sample_file.txt'.split()
subprocess.call(command_zip)

zip warning: name not matched: ./sample_file.txt
zip error: Nothing to do! (try: zip -r -e -Ptest test.zip . -i ./sample_file.txt)

有办法做到这一点吗?

0 个答案:

没有答案