using subprocess.Popen env parameter

E

enda man

Hi,

I want to use the env parameter to subprocess.Popen to pass in a path
to a location the process needs to run,
I do have a env variable already called MS_VC_PATH and I want to add
to it, not set up more in the PATH variable.

/////
ms_vc_path=os.environ['MS_VC_PATH']
cl_path = ms_vc_path + '\VC\bin'
lib_vc_path = ms_vc_path + '\VC\lib'
myenv = os.environ
myenv["PATH"] = cl_path + ";" + lib_vc_path + ";" + myenv["PATH"]

subprocess.Popen("midl /D \"_DEBUG\" /nologo /char signed /env win32 /
Oicf /tlb \"ActivexPlugin.tlb\" /h \"ActivexPlugin_i.h\" /iid
\"ActivexPlugin_i.c\" /proxy \"ActivexPlugin_p.c\" /error stub_data
ActivexPlugin.idl", env=myenv)

///

but it seems that midl can not see the new path I am sending to it
using the env variable, am I using env correctly?

here is my output:
midl : command line error MIDL1005 : cannot find C preprocessor cl.exe

Any help?
EM
 
N

Nobody

cl_path = ms_vc_path + '\VC\bin'

The backslash is used as an escape character within string literals.
Either use raw strings:

cl_path = ms_vc_path + r'\VC\bin'

or escape the backslashes:

cl_path = ms_vc_path + '\\VC\\bin'

or use os.path.join():

cl_path = os.path.join(ms_vc_path, 'VC', 'bin')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top