Reputation: 3
I'd like to have a method to do 3 things at the same time:
Create a subprocess that run the vsvars32.bat (visual studio batch file)
In this subprocess set the environment variables.For example in a cmd lines:
- SET MYDIR = C:\This\this\here
- SET DIR = %MYDIR%
- SET PATH = %DIR%\bin;%PATH%
Also into this subprocess call the perl script with his parameters. in cmd:
- cd %MYDIR%\SOURCE\FILES
- My_Perl.pl -Name Mac -owner -details -vs_version 2005 -Run_type rebuild
I created a code in python:
myenv = {'MYDIR' : 'C:\This\this\here', 'DIR' : '%MYDIR%', 'PATH' : '%DIR%\bin;%PATH%'}
batchCmd = 'c:/.../vsvars32.bat'
perlCmd = 'c:/.../MyPerl.pl'
perlValues = ['-Name', 'Mac', '-owner', '-details', '-vs_version', '2005', '-Run_type', 'rebuild']
process = subprocess.Popen(['cmd','/c', batchCmd ,'&&', perlCmd, perlValues], shell=False, stdin = subprocess.PIPE, stdout = subprocess.PIPE, env = myenv)
The problem is that the function subprocess.popen not recognize myenv values and the perlValues.
Upvotes: 0
Views: 2289
Reputation: 5069
Try adding perl.exe to perl cmd.
perlCmd = 'C:\perl\perl.exe c:/.../MyPerl.pl'
Second, you use backslash for path in one place, slash in the other. That maybe a problem.
myenv = {'MYDIR' : 'C:\This\this\here', using backslash
'%DIR%\bin;%PATH%'} using slash
Simply try to print out the env, to see that the environment is populated or not:
process = subprocess.Popen(['cmd','/c', 'set'], shell=False, stdin = subprocess.PIPE, stdout = subprocess.PIPE, env = myenv)
Also, you forgot to cd before executing perl script.
process = subprocess.Popen(['cmd','/c', batchCmd ,'&&', 'cd %MYDIR%\SOURCE\FILES', '&&', perlCmd, perlValues], shell=False, stdin = subprocess.PIPE, stdout = subprocess.PIPE, env = myenv)
regards,
Upvotes: 1