にスペースを使用してWindows上でサブプロセスを経由してコマンドを実行している、私が行いますはWindows用、Pythonでコマンドを実行するには、ファイル名
lsCommand
はbashコマンドを構成する文字列のリストである
import subprocess
subprocess.check_output(lsCommand, shell=True)
。空白を含む入力がある場合を除いて、これは機能します。
がしようとするとcp "test 123" test123
を行うには:たとえば、名前を変更+コピー、それは私がcp "test" "123" test123
をやろうとしています考えているので
lsCommand = ['cp', 'test 123', 'test123']
subprocess.check_output(lsCommand, shell=True)
は失敗します。エラー(Googleのストレージのものをやって):
python: can't open file 'c:\GSUtil\gsutil.py cp -n gs://folderl/test': [Errno 22] Invalid argument
その後、私は
subprocess.check_output('cp "test 123" test123', shell=True)
同じたわごとをしてみてください。何か案は?
なぜ 'shell = True'を使用していますか? 'shell = True'のないリストではうまくいくと思います。 – zondo
@zondoは窓にはない、いいえ。 Linux yay – Roman
も参照してください。http://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess – tripleee