lua-users home
lua-l archive

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


On 14/01/2013 11.47, Thijs Schreijer wrote:

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

Thx. That helped find it; I should have used %ERRORLEVEL% and not %ERROR_LEVEL%

Silly me. (again)

Thijs

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




I was just about to post a thing about "ERRORLEVEL", but you did it yourself :-). Anyway you might find the following link useful:

http://ss64.com/nt/if.html

especially when it advices to use setlocal in your batch file (YMMV).

OT: In general I find http://ss64.com/nt quite useful when coping with Windows shell quirks.

Cheers

-- Lorenzo