0

I'd like to have a method to do 3 things at the same time:

  1. Create a subprocess that run the vsvars32.bat (visual studio batch file)

  2. 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%
  3. 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.

2
  • 1
    And what is the error message you got? Please always provide the full traceback. Commented Mar 21, 2012 at 18:02
  • "ERROR: Can't locate FileX.pl in %MYDIR%/files/scripts at C:\...\MyPerl.pl line 317." *Show %% instead the real Path = DIR+/files/scripts. and the file is in this directory. Commented Mar 21, 2012 at 22:06

1 Answer 1

1

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,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.