lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


There is some introduction about the "errorlevels":
It just seemed that "errorlevel" can only be used with "if".
Finally,if you want to use script on windows, "cygwin" is the suggestion.

> From: thijs@thijsschreijer.nl
> To: lua-l@lists.lua.org
> Date: Mon, 14 Jan 2013 10:23:42 +0000
> Subject: commandline return codes
>
> I'm having trouble getting the following to work (reduced example, fixed bad line wrap).
>
>
> "script1.lua"
> print("Final result from os.execute():", os.execute("start.bat"))
>
> "start.bat"
> @ECHO OFF
> echo Started batchfile
> lua.exe script2.lua
> echo Batch received %ERROR_LEVEL% as exitcode
> exit /B %ERROR_LEVEL%
>
> "script2.lua"
> local exitcode = "25"
> print("========================")
> print(" Script 2 calling")
> print(" exiting with",exitcode)
> print("========================")
> os.exit(exitcode)
>
>
> What I'm trying to do is catching a return code. Script1 calls the batchfile, which calls script2. The batch file has to be in between to do some OS magic.
>
> This is the output;
> C:\Users\Thijs\Dropbox\LUAPRO~1\busted\test\src>script1.lua
> Started batchfile
> ========================
> Script 2 calling
> exiting with 25
> ========================
> Batch received as exitcode <===
> Final result from os.execute(): 0
>
> C:\Users\Thijs\Dropbox\LUAPRO~1\busted\test\src>
>
> So the exitcode to the os.exit() call in script2 does not get passed on to the %ERROR_LEVEL% environment variable(marked with <===). I'm running this on Windows7, using Lua for Windows.
>
> Any ideas?
>
> Thijs
>
>