On Feb 5, 9:17 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote: > En Thu, 05 Feb 2009 17:34:29 -0200, Andrew <andrew.replo...@gmail.com> > escribió: > > > > > On Dec 16 2008, 5:11 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> > > wrote: > >> En Tue, 16 Dec 2008 17:21:35 -0200, Andrew <andrew.replo...@gmail.com> > >> escribió: > > >> > On Dec 16, 12:50 pm, Christian Heimes <li...@cheimes.de> wrote: > >> >> Andrew schrieb: > > >> >> > I'm running into a strange situation with getting incorrect > >> >> > returncodes / exit status from python subprocess.call. I'm using a > >> >> > python script (runtime 2.6.1 on windows) to automate the deploy of > >> >> > java applications to glassfish application server. Below is an >> > >> > example > > I've tried this several ways now. It seems to be something specific > > with python and asadmin.bat. > > > I've tried the following manually in the cmd.exe prompt: > > [examples showing %ERRORLEVEL% correctly set when running from the command > line, but subprocess.call doesn't get it] > > > Notice how python never gets the correct returncode from asadmin.bat > > but I can get the correct returncode from the shell every time. Can > > anyone tell me why Python wouldn't be able to get the correct > > returncode for asadmin? > > The last exit code set by a command *should* propagate as the exit code of > the whole .bat, then as the exit code of the cmd.exe instance that runs > it, and finally Python *should* receive that value. Some old Windows > versions didn't behave like that, but AFAIK XP does the right thing here. > Unless asadmin.bat is playing tricks with %ERRORLEVEL% or something. > Can you post the contents of asadmin.bat? > > Without looking into it, I can think of a few alternatives: > > - rewrite asadmin.bat in Python, if feasible. Some scripts just check/set > a few environment variables and execute some process at the end, and > that's all; in this case it should be easy to emulate the same thing in > Python. > > - try using another layer of your own, e.g., my_asadmin.bat: > > call asadmin.bat %* > exit /b %ERRORLEVEL% > > - variation: write the exit code somewhere: > > call asadmin.bat %* > echo %ERRORLEVEL% > asadmin.err > > and read asadmin.err from Python. (I've used something like this in a > chain Win32 process --> 16 bits GUI application --> .bat script --> old > DOS executable) > > -- > Gabriel Genellina
Thanks Gabriel, Someone on the glassfish forums also pointed out the "exit /B %ERRORLEVEL%" for the bottom of the batch file and that corrected the issue for me. As well as not using that and removing "endlocal" which I admit I have no clue what that does. Removing endlocal seems to cause the batch script to pass out the correct returncode. Thanks everyone for your input and assistance =] Andrew -- http://mail.python.org/mailman/listinfo/python-list