Sign in to follow this  
Followers 0
giogio

return text to window command shell

6 posts in this topic

i have an application that execute window command shell, the returned value is then processed by the application,

i made a small au3 script and the output value is showed by:

Msgbox(1,"my value is: ",$Output).

The question is;

1) how to to run my exe script from the window command shell and return the value to the shell?

Many thanks for your help

By

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

i have an application that execute window command shell, the returned value is then processed by the application,

i made a small au3 script and the output value is showed by:

Msgbox(1,"my value is: ",$Output).

The question is;

1) how to to run my exe script from the window command shell and return the value to the shell?

Many thanks for your help

By

If the value is numeric and fits in a 32bit DWORD, you can just use it as a parameter on EXIT:

If @error Then
     Exit 1234567
Else
     Exit 0
EndIf

It will show up in the command shell as %ERRORLEVEL%.

:)

Edit: typo

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

i made a test.exe

this is the script:

If @error Then

Exit 0

Else

Exit 12321

EndIf

then i execute it from window using:

cmd.exe /C c:\test.exe

no result.

were i am wrong?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

i made a test.exe

this is the script:

If @error Then

Exit 0

Else

Exit 12321

EndIf

then i execute it from window using:

cmd.exe /C c:\test.exe

no result.

were i am wrong?

Well, to get a result, you would have to run from a command line manually or via a batch file and do something like this:

C:\Test.exe
echo %ERRORLEVEL%

But something seems to have changed.

I compiled a one line script from this:

Exit 1oÝ÷ Ø  ݧ"»§¶Åçë¢f¢iÙbæ§vØ^ç! DQ9ÄT² zݽêò¶)"ÇÚz­¶)à¢yr¶¬µ«n²ØZ¶Ø^r©Wëh"اµêé­ë^®+)æ¬yÜ"¶­±é_jwg¢ÛayÊ&©Ýy×±×(7öjkzÛr²êÞ¶­ºÇ¶(®K§²êÞØ­!Ê'~*æyØ­Á«#ºËm觵êé­ë^¯l²Ö­ºÆò~Üx-ç(¥zÚnº$z{®*mjëh×6Exit _DingleBerry()

When I run the .exe, it pops the expected error message, the returns 2 for %ERRORLEVEL%. So we are only getting the AutoIt interpreter's status code, not the parameter from 'Exit'.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Figured out my confusion, which I think I had figured out before (like a year or more ago), but this is not something I do every day and it was forgotten.

The basic problem is that the shell environment of the CMD console, and the shell environment of a running batch file (.bat or .cmd) are NOT the same.

If you run a compiled AutoIt script MANUALLY from the command line, by typing in "Test.exe" and hitting enter, then typing in "echo %ERRORLEVEL%" and hitting enter again, you only get the return code of the spawned windows environment that runs the executable, which in the case of a compiled AutoIt script is the exit code from the AutoIt interpreter, not the script's "Exit (123)" function. That is what I was doing in the above post.

If you create an actual batch file like this:

C:\Temp\Test.exe
echo Return code was %ERRORLEVEL%

Then run the batch file and you get the actual parameter passed to the Exit function in the AutoIt script.

Some things are just different inside the shell of a batch file. Remember, for example, that with a DOS command line like this:

FOR /L %i IN (2, 2, 10) DO ECHO Even numbers:  %i

You have to double up the '%' on variable references inside a batch file but not when typing at the console:

FOR /L %%i IN (2, 2, 10) DO ECHO Even numbers:  %%i

So AutoIt's "Exit (1234567)" will behave as expected inside an actual batch file, but not when using manual commands at the console.

:)

P.S. This doesn't address the original point about how to send TEXT to CMD shell environment that runs your compiled script. 'Exit (n)' can only return a signed 32bit integer.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

To return a text message to prompt you need to convert your code AU3 for DOS, using the program Aut2exe.exe.

Thus the function ConsoleWrite sends message to the terminal.

Share this post


Link to post
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
Sign in to follow this  
Followers 0