Jump to content

Passing information to DOS-variable


Recommended Posts

I want to run an AutoIT-script from a batchfile, let it calculate some stuff, and pass the results to a variable in that batchfile.

To be precise, I want the .exe-file to return a value. Is it possible?

Your help will be greatly appreciated.

Link to comment
Share on other sites

It maybe possible via piping. You could possibly accomplish this by pipe back to the cmd interpreter before exit. I have not done this before, so my experience is nil. You would be using STDERR to STDOUT, I think? Someone else may have a better idea?

Link to comment
Share on other sites

  • 4 weeks later...

I gotta bump this old topic, as I searched and searched, but haven't found an answer. :/

The posted functions sends commands to an app it launches. I want to pass commands to the app it launched from.

Thanks for the answer tho :(

Edited by Nanaki
Link to comment
Share on other sites

Guest netstroller

I gotta bump this old topic, as I searched and searched, but haven't found an answer. :/

The posted functions sends commands to an app it launches. I want to pass commands to the app it launched from.

Thanks for the answer tho :(

<{POST_SNAPBACK}>

I appologize if this is a bad suggestion, I'm not too knowledgeable on this but thought I'd give it a stab since there's no other posts lately.

My idea is, if the posted functions do send commands to an app it launches, as stated above, maybe you could have one of those functions send a command to an app to set an environment variable. Then in your original app call or use that environment variable as your command.

ie. "start %WhatIWant%"

Link to comment
Share on other sites

The answer is simple.

Check the help file for these two commands.

EnvSet ( "envvariable" [, "value"] )

EnvGet ( "envvariable" )

Of course, you'll have to get around the problem of

"A environment variable set in this way will only be accessible to programs that AutoIt spawns (Run, RunWait). Once AutoIt closes, the variables will cease to exist."

Maybe if the variable already exists, it won't get trashed when autoit exits.

Edited by Blue_Drache

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

Link to comment
Share on other sites

This looks clumsy, but it works pretty well. The concept is to have your AutoIt script save its response to a file, and then have the batch file read the value from the text file into an environment variable. Note that this requires Windows 2000/2003/XP; Win9x doesn't support the extended FOR command necessary.

In the example code below, we'll change the value of environment variable "_test" from "value" to "MynewValue".

Here is the batch file.

set _test=value
start "" /w "C:\Program Files\AutoIt3\AutoIt3.exe" C:\test.au3 %temp%\return.ini
for /f "delims== tokens=1,2" %%a in (%temp%\return.ini) do if '%%a'=='_test' set _test=%%b
del %temp%\return.ini

Sample Autoit code:

If $Cmdline[0] > 0 Then
  IniWrite($CmdLine[1], "Return", "_test","MynewValue")
EndIf

BlueBearr

BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

@netstroller: if you, per example, write away an environment variable with an AutoIT-app launched from a batchfile, that batchfile will not be able to use that variable. Batchfiles read all the variables at the start, so only the next batchfiles will be able to read it.

@Blue_Drache: that is indeed for using variables within a certain AutoIT-app, but that won't return the value. :/

@bluebearr: that would be indeed a solution, but it's not quite what I'm looking for. This is what I want:

SET VARIABLE=AutoItApp.exe

Thanks for your help and toughts tho :(

Link to comment
Share on other sites

@netstroller: if you, per example, write away an environment variable with an AutoIT-app launched from a batchfile, that batchfile will not be able to use that variable. Batchfiles read all the variables at the start, so only the next batchfiles will be able to read it.

@Blue_Drache: that is indeed for using variables within a certain AutoIT-app, but that won't return the value. :/

@bluebearr: that would be indeed a solution, but it's not quite what I'm looking for. This is what I want:

SET VARIABLE=AutoItApp.exe

Thanks for your help and toughts tho :(

<{POST_SNAPBACK}>

So what I am understanding you to say is that you want the AutoIt script to return a variable as if it was a function in the batch script? Why cant you just send the variable back to the open cmd.exe window? Or use a Exit(number) then in the batch code use an if statement to figure out what each number is going to mean in a string.

Little extra coding in the batch, but not hard. Also why not just have AutoIt do the whole script and not a mix with batch?

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Because I want to use AutoIT during a batchscript do change a variable dynamically. I can't use errorlevels because the options are too extensive. :/

<{POST_SNAPBACK}>

Okay... I am guessing you dont want to do the whole thing in AutoIt hence the batch.

That is fine.

Now the solution I came up with was when the AutoItApp.exe returned an integer on exit (set by Exit(number)) Say the integer for one option is 33 (whatever you choose) You would then have a part of the batch program that would process something like the following.

If VARIABLE = 33 Then VARIABLE = "The String You Really Want".

The only way that wouldnt really work is if AutoIt is trying to grab some sort of dynamic info which is my guess.

If you could please explain more about your batch program and what it is trying to do and maybe what you want autoit to do and when I maybe be able to further assist.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Maybe use the registry for transfer, if is not an overloading concept to use ?

Au3.exe
RegWrite('HKCU\Temp', 'variable', 'Reg_sz', $var)

Batch.bat
SET VARIABLE=REG QUERY "HKCU\Temp" /v variable
Link to comment
Share on other sites

Well, I want to detect a network path and install stuff from it with the batchfile.

Next, after some time, I want to change that variable, again with a value detected with the AutoIt-app.

I guess it can't be done on the way I had in mind (though MHz said something about "piping", what does this mean exactly?).

The way MHz suggested is already alot better, thanks for that. :( I'm still hoping for AutoIT returning values tho ^^

Link to comment
Share on other sites

I guess it can't be done on the way I had in mind (though MHz said something about "piping", what does this mean exactly?).

<{POST_SNAPBACK}>

Well....the easiest way that I can think of is this command line here:

DIR C:\ | MORE

The contents of the directory command are passed to or "piped" to the "MORE" command. This puts in a "press any key to continue" or a "--more--" at the end of 24 lines.

Another command (although more destructive) is:

ECHO Y | FORMAT C:\ /u /v:pwnt > nul

It answers the yes/no prompt that format generates and redirects the output to the nul operator.

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

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...