Jump to content

Returning values from a compiled script


Recommended Posts

Guest Philipm
Posted

Hi Everyone,

I have just started using AutoIT and I have to say I LOVE IT. I am however facing a slight problem;

I have written and compiled a short script to detect when dialog boxes appear. The resulting compiled script is called from a VB script. What I need to do is pass back to the VB script a number, from the AutoIt compiled script when certain dialogs are thrown. I cant seem to find a way to do this!!!!

From what I can see, AutoIT doesnt seem to implement StdOut or StdErr functionality...and I tried using the Exit funtion to return a number and then using VB script to read the %errorlevel%, but this seems to always return a value of 0 once the script has completed.

Is there somthing I am doing incorrectly????

Any help or ideas alaways appreciated.

Phil

Posted

Hi Everyone,

I have just started using AutoIT and I have to say I LOVE IT. I am however facing a slight problem;

I have written and compiled a short script to detect when dialog boxes appear. The resulting compiled script is called from a VB script. What I need to do is pass back to the VB script a number, from the AutoIt compiled script when certain dialogs are thrown. I cant seem to find a way to do this!!!!

From what I can see, AutoIT doesnt seem to implement StdOut or StdErr functionality...and I tried using the Exit funtion to return a number and then using VB script to read the %errorlevel%, but this seems to always return a value of 0 once the script has completed.

Is there somthing I am doing incorrectly????

Any help or ideas alaways appreciated.

Phil

<{POST_SNAPBACK}>

you could always write the number to an .ini file.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Posted

Just end your AutoIt script with "Exit <number>":

Exit 5
Then your VB script should be able to simply use the return value of the AutoIt script to proceed as needed.

Guest Philipm
Posted

you could always write the number to an .ini file.

<{POST_SNAPBACK}>

Thanks for the help Sugi, but your suggestion doesnt seem to work. I assume that once a script is terminated with an Exit <number>, I should be able to read back the number from %errorlevel%. The errorlevel however does not seem to be set correctly, always resulting in 0, no matter what number I exit with.

Also...is the syntax for Exit, Exit <number> or Exit (<number>) with the parenthesis???

TIA....

Phil

  • 3 weeks later...
Posted (edited)

Exit [return code]

return code :: [optional] Integer that sets the script's return code. This code can be used by Windows or the DOS variable %ERRORLEVEL%. The default is 0. Scripts normally sets an errorlevel of 0 if the script executed properly; error levels 1 and above typically indicate that the script did not execute properly.

Remarks

The parameter, if included, can be enclosed in parentheses. Thus, the following are equivalent: Exit, Exit 0, and Exit(0). However, Exit() is invalid.

*Edit: And this seems to work fine with a batch file.

test.au3

Exit 4

test.bat

@echo off
test.au3
echo au3 errorlevel: %errorlevel%

test.exe
echo exe errorlevel: %errorlevel%

result

au3 errorlevel: 4
exe errorlevel: 4

Guess it's a VBScript problem.

Edited by Saunders
Posted

Don't know if this helps, but I was able to return a value with SetError:

vb.au3

SetError (2)

RunWait(@ComSpec & " /c c:\temp\vb.vbs " & @error )

vb.vbs

Set objArgs = Wscript.Arguments

Wscript.Echo "Error Number: ", objArgs.item(0)

Posted

I think he wants to do the reverse. He wants to use VBScript to run an AutoIt script and retrieve a value from it.

You don't even need to use SetError to implement your example.

If you RunWait(@ComSpec & " /c c:\temp\vb.vbs helloHelloHELLO")

It will work the same way.

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
×
×
  • Create New...