Note that there are some explanatory texts on larger screens.

plurals
  1. POCall subprocess.Popen() when the working directory is on a UNC path, not a mapped drive
    primarykey
    data
    text
    <p>I would like to run an executable that performs some processing on a dataset located on a remote filer. As part of the design, I'd like the location of the filer to be flexible and something that's passed to my python program at runtime.</p> <p>I've put together the following bit of code that illustrates my problem, but using the <code>python</code> command, so anyone can run this:</p> <pre><code>#!/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') </code></pre> <p>This works great as long as <code>iwd</code> is on a share that's be mapped to a drive letter on the machine. But if <code>iwd</code> is a UNC path the <code>subprocess.Popen()</code> call ends up with stderr output, which in turn throws the IOError exception:</p> <pre><code>Traceback (most recent call last): File "test.py", line 19, in &lt;module&gt; 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. </code></pre> <p>Is there a way to make this subprocess call work <em>without</em> resorting to parsing <code>iwd</code> and making a temporary drive mount on the machine that exists while the subprocess command executes? I want to avoid having to manage the creation and cleanup of drive mounts. And of course, I'd rather not have to deal with (albeit unlikely) case where all drive letters are currently in use on the machine.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload