让我们说我运行的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)
有办法做到这一点吗?