リモートファイラーにあるデータセットに対して何らかの処理を実行する実行可能ファイルを実行したいと考えています。設計の一環として、ファイラーの場所を柔軟にし、実行時に Python プログラムに渡すものにしたいと考えています。
私の問題を説明する次のコードをまとめましたが、python
コマンドを使用しているため、誰でもこれを実行できます。
#!/usr/bin/env python
import os
import subprocess
def runMySubProcess(cmdstr, iwd):
p = subprocess.Popen(cmdstr,
shell=True,
cwd=iwd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
if stderr:
raise IOError, stderr
return stdout
if __name__ == '__main__':
print runMySubProcess('python -h', 'C:\\')
print runMySubProcess('python -h', '\\\\htpc\\nas')
iwd
これは、マシンのドライブ文字にマップされている共有上にある限り、うまく機能します。しかし、iwd
が UNC パスの場合、subprocess.Popen()
呼び出しは stderr 出力で終了し、IOError 例外がスローされます。
Traceback (most recent call last):
File "test.py", line 19, in <module>
print runMySubProcess('dir', '\\\\htpc\\nas')
File "test.py", line 14, in runMySubProcess
raise IOError, stderr
IOError: '\\htpc\nas'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
サブプロセスコマンドの実行中に存在するマシンに一時ドライブを解析してマウントすることに頼らずに、このサブプロセス呼び出しを機能させる方法はありますか? iwd
ドライブ マウントの作成とクリーンアップを管理する必要はありません。そしてもちろん、すべてのドライブ文字が現在マシンで使用されている場合 (ありそうもないことですが) に対処する必要はありません。