Jump to content

Exit 1. Yet $? and $LastExitCode not working


rcmaehl
 Share

Go to solution Solved by Danyfirex,

Recommended Posts

Hi all,

I'm attempting to get the exit state of an AutoIt script after using

Exit 1

Exit 1 can literally be the only line in the script yet both $? and $LastExitCode are unable to detect that it exited with an error. I'm assuming this is because the script sets %ERRRORLEVEL% but I am unsure.

image.png.711e30899da77fc0cfd01bd11d2cab12.png

I've also tried the below suggestion but it also seems to not work

image.png.e444cb84d78062f31fc4048ef63e04e5.png

What am I doing wrong?

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Compile e.g. (Scriptname = ReturnExitvalue.au3)

Global $g_sValue
$g_sValue = InputBox("Test", "Enter a number between 1 and 99 : ", "0")
MsgBox(4096, "", "%ERRORLEVEL% = "& $g_sValue)
Exit($g_sValue)

Run via .cmd :

@echo off
echo starts Exe and displays the Returnvalue (Exit)
cd %~dp0
ReturnExitvalue
echo.
echo %ERRORLEVEL%
pause

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

5 minutes ago, Musashi said:

Compile e.g. (Scriptname = ReturnExitvalue.au3)

Global $g_sValue
$g_sValue = InputBox("Test", "Enter a number between 1 and 99 : ", "0")
MsgBox(4096, "", "%ERRORLEVEL% = "& $g_sValue)
Exit($g_sValue)

Run via .cmd :

@echo off
echo starts Exe and displays the Returnvalue (Exit)
cd %~dp0
ReturnExitvalue
echo.
echo %ERRORLEVEL%
pause

Okay so there's no way to do this through powershell, has to be console?

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

2 minutes ago, rcmaehl said:

Okay so there's no way to do this through powershell, has to be console?

Not necessarily, but that's how I've always evaluated the return value so far. There has been no reason yet for me to do it otherwise ;).

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • Solution

Hello. Do it like this.

(Start-Process App.exe -PassThru -Wait).ExitCode

 

Saludos

Link to comment
Share on other sites

On 8/16/2021 at 1:13 PM, Danyfirex said:

Hello. Do it like this.


(Start-Process App.exe -PassThru -Wait).ExitCode

 

Saludos

THANK YOU

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...