Menu

#17 Exitcode (Errorlevel)

open
nobody
None
5
2003-06-27
2003-06-27
Tom Arn
No

I miss the possibility to specify an Exitcode for a
Dialect program that will be available by the calling
program through ERRORLEVEL.

The global frame might be a good place to define the
exitcode, e.g.
global.exitcode = 0 should be default and a Dialect
program could change that to any other numeric
exitcode. The Interpreter should then return that value
to the calling program when the dialect program ends.

Example:

@echo off
rem This is a batch file
rem
rem Call the dialect program
MyDialectProgram.exe
rem check the exitcode
if errorlevel 0 if not errorlevel 1 goto ok
goto error

Tom

Discussion

  • A.H. Banen

    A.H. Banen - 2003-06-28

    Logged In: YES
    user_id=423153

    Tom,
    I see you asked for this a long time ago
    (\msgboard\messages\649.html June 07, 19100 at 02:05:03
    on the old Aristar message board).
    I think (like George in his response) that this would be a nice
    feature. How about using AbortProgram (which should be
    revised anyhow) to force an exit code?
    Andr

     
  • Tom Arn

    Tom Arn - 2003-06-30

    Logged In: YES
    user_id=462273

    Well, AbortProgram does not allow to set an Exit Code ...

    Currently, only this works: kernel32.ExitProcess(ExitCode) ...

    Tom

     
  • A.H. Banen

    A.H. Banen - 2003-06-30

    Logged In: YES
    user_id=423153

    Tom,
    I did not mean AbortProgram already can be used to set an
    exit code, I just proposed enhancing AbortProgram to do so in
    the future.
    There is a prossible (small?) problem when using an exit (and
    thus an exit code ) when running a programming 'from the
    editor' (t.i. not as an exe). In such a case an exit will also
    end the editor which is not very handy (does
    kernel32.ExitProcess do this?). Also the exitcode should
    become visible when running a program 'in the editor' so
    maybe an errorcondition should be raised when using it that
    way.
    From what I've already seen in the code AbortProgram ends a
    program running by doing some cleaning up and then calling
    AllocNil() returning the exit value of this function to the
    interpreter.
    So both AbortProgram and the internal function AllocNil should
    be used for setting the exitcode.
    Andr

     
  • Bill Littlejohn

    Bill Littlejohn - 2003-11-07

    Logged In: YES
    user_id=420523

    While I see the logic behind using AbortProgram() to return an
    errorlevel - would this work in practice? For my purposes, I
    want errorlevel returned for use with PSEXEC from
    sysinternals.com. So assuming that everything goes well in
    my dialect program, I need to exit normally and return the
    errorlevel. If this functionality is only available in AbortProgram
    () then you'll be forced to end every program with an
    abortprogram(), which has never worked right. I always get
    an empty message box titled "error".
    In any case - somethings better than nothing.
    I third the motion. : )

    How difficult is it to use the kernel32.ExitProcess(ExitCode)
    method? Couldn't I just set this up as a module for use in the
    programs that require it?

     
  • A.H. Banen

    A.H. Banen - 2003-11-07

    Logged In: YES
    user_id=423153

    Bill,
    To correct a sligth misunderstanding: using AbortProgram(
    exitcode) would only override a default exit code (error level)
    of 0. The default and the method to allow the user to
    override it are both currently lacking.
    The error message box when AbortProgram is used in a
    Dialect exe is a known error; the source code doesn't make
    very clear where this error comes from :(

    Setting up the kernel32.ExitProcess is very easy, but I
    experienced problems using Windows XP (the test application
    simply crashed) and a cmd command processor box.
    But here is the code anyhow:

    import "system"
    kernel32 = system.dll( "kernel32.dll" )
    kernel32.__loadpfunc__( "ExitProcess","ExitProcess", 'void ,
    [ 'int ])

    import "gui"

    w = gui.window( "Exit test", [10,10,60,120 ] )
    b = gui.button( w, "Exit now", w.clientrect )

    dwExitcode
    b. onclick = func()
    dwExitcode = 3
    kernel32.ExitProcess(dwExitcode)
    endfunc

    w.onclose = func()
    # default
    dwExitcode = 0
    kernel32.ExitProcess(dwExitcode)
    return true
    endfunc

    gui.enter()

    Note: this code doesn't work on my Windows XP

    Andr

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.