我在使用Python 2.7的Mac OS X上;使用subprocess.call
與zip
失敗,但在shell成功運行相同命令。這裏是我的終端的副本:爲什麼python subprocess zip失敗,但在shell中運行?
$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call(['zip', 'example.zip', 'example/*'])
zip warning: name not matched: example/*
zip error: Nothing to do! (example.zip)
12
>>> quit()
$ zip example.zip example/*
adding: example/file.gz (deflated 0%)
我也嘗試過使用完整路徑並得到相同的結果。
行爲取決於系統和適用於Windows,同時由於通過@MartijnPieters解釋 – alko