Xenobiologist Posted February 6, 2006 Posted February 6, 2006 HI, I searched for it, but I cannot find it. What I am trying to do is starting my script.exe in a DosBox or something and gave a value back when the script ends. E.g: start script.exe The script reads a txt file extracts the value for version= ... and returns it. So, the script which starts the autoit.exe gets the value example 1.16 How can I do it? ConsoleWrite doesn´t work. Return although doesn´t seem to work. So long, Mega P.S.: I´m sure there must be a simple answer, but I cannot find it. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
flaxcrack Posted February 6, 2006 Posted February 6, 2006 HI, I searched for it, but I cannot find it. What I am trying to do is starting my script.exe in a DosBox or something and gave a value back when the script ends. E.g: start script.exe The script reads a txt file extracts the value for version= ... and returns it. So, the script which starts the autoit.exe gets the value example 1.16 How can I do it? ConsoleWrite doesn´t work. Return although doesn´t seem to work. So long, Mega P.S.: I´m sure there must be a simple answer, but I cannot find it. RunWait(@ComSpec & " /k echo "$var) [quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()
Xenobiologist Posted February 6, 2006 Author Posted February 6, 2006 RunWait(@ComSpec & " /k echo "$var) Thanks, you forgot the & it must be RunWait(@ComSpec & " /k echo " & $var) Hmmh, but that is still not what I wanted. Now, the script.exe opens an extra DOS-window. I want the script to paste the return value to the one where the script was started. Exactly, my prob is, I want to catch the return value of my autoitscript, so that I can work with the result in another script. Claer? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Valuater Posted February 6, 2006 Posted February 6, 2006 (edited) you were working on somethng like this earlier #include <file.au3> Global $file = FileOpen ( "C:\temp\check.txt", 0) Global $ver = 1.3 $check = FileReadLine ( $file, 1 ) Msgbox (0, "Titel", $ver & @CRLF & $check) if $ver >= $check Then MsgBox ( 0, "Update", "Your version is up to date" ) Else MsgBox ( 0, "Update", "Your Version is out of date" ) EndIf FileClose($file) cant you write it to a file, then have the other script read it?? 8)i Edited February 6, 2006 by Valuater
cdkid Posted February 6, 2006 Posted February 6, 2006 ClipPut($var) WinActivate("commandwindowtitlehere") send(ClipGet()) --maybe? ~cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Xenobiologist Posted February 6, 2006 Author Posted February 6, 2006 Valuater: you were working on somethng like this earlier@Valuater: No, that was an example where I helped somebody else. Valuater: cant you write it to a file, then have the other script read it?? @Valuater: No, the info I need to give back is already in a file, and I read it with myscript.exe. @cdKid: Thanks, I will test it, although it is not a very nice solution. @all: If an script.exe written in autoit --- ends, is there a return code or value? Maybe it runs perfectly fine and the return code is 0. Can I get that value anayway? And if I can get it, can I manipulate it? I want to use a whole script.exe as to say as a function which gives a defined return value back. Crazy: but something like this: func script.exe() read the version out an txt file return $version That is what I have so far. #include <file.au3> If $CmdLine[0] > 0 Then $path = $CmdLine[1] Else $path = @WorkingDir & "\settings.ini" EndIf version() Func version() Dim $aRecords If Not _FileReadToArray($path, $aRecords) Then RunWait(@ComSpec & " /k echo " & "File not found in " & $path & ' ErrorCode: ' & @error) Exit EndIf For $x = 1 To $aRecords[0] If StringInStr($aRecords[$x], "version =") Then $version = StringMid($aRecords[$x], 11, 4) RunWait(@ComSpec & " /k echo " & $version) Else ContinueLoop EndIf Next EndFunc ;==>version So long and thanks for your replies, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
MHz Posted February 6, 2006 Posted February 6, 2006 DOS Batch file@echo off Test.exe echo %errorlevel% pauseTest.exeExit 1234Exit only supports Integers though.
DaveF Posted February 6, 2006 Posted February 6, 2006 (edited) Continuing MHz's post, if you're reading floating point numbers with no more than a few, consistent decimal places you can multiply by 100/1000/whatever before you call Exit in the child script, then divide by the same value in the parent script. If the numbers/strings that you're reading aren't consistent or floating point numbers then you'd be better off with ConsoleWrite (child script) and StdoutRead (parent script). [Edit: Clarification.] Edited February 6, 2006 by DaveF Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.
Xenobiologist Posted February 6, 2006 Author Posted February 6, 2006 Continuing MHz's post, if you're reading floating point numbers with no more than a few, consistent decimal places you can multiply by 100/1000/whatever before you call Exit in the child script, then divide by the same value in the parent script. If the numbers/strings that you're reading aren't consistent or floating point numbers then you'd be better off with ConsoleWrite (child script) and StdoutRead (parent script). [Edit: Clarification.] Thank you, but ... I tried this #include <file.au3> Global $version = 0 If $CmdLine[0] > 0 Then $path = $CmdLine[1] Else $path = @WorkingDir & "\settings.ini" EndIf version() Func version() Dim $aRecords If Not _FileReadToArray($path, $aRecords) Then RunWait(@ComSpec & " /k echo " & "File not found in " & $path & ' ErrorCode: ' & @error) Exit EndIf For $x = 1 To $aRecords[0] If StringInStr($aRecords[$x], "version =") Then $version = StringMid($aRecords[$x], 11, 4) $version *= 100 Else ContinueLoop EndIf Next EndFunc ;==>version Exit($version) Batch file: @echo off start c:\downloads\Autoit-skripte\entwicklung\readversion.exe c:\downloads\Autoit-skripte\entwicklung\settings.ini echo %errorlevel% echo %errorlevel% / 100 pause Output is: 0 0 / 100 Did I make anything totally wrong? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
flaxcrack Posted February 6, 2006 Posted February 6, 2006 Thank you, but ... I tried this #include <file.au3> Global $version = 0 If $CmdLine[0] > 0 Then $path = $CmdLine[1] Else $path = @WorkingDir & "\settings.ini" EndIf version() Func version() Dim $aRecords If Not _FileReadToArray($path, $aRecords) Then RunWait(@ComSpec & " /k echo " & "File not found in " & $path & ' ErrorCode: ' & @error) Exit EndIf For $x = 1 To $aRecords[0] If StringInStr($aRecords[$x], "version =") Then $version = StringMid($aRecords[$x], 11, 4) $version *= 100 Else ContinueLoop EndIf Next EndFunc ;==>version Exit($version) Batch file: @echo off start c:\downloads\Autoit-skripte\entwicklung\readversion.exe c:\downloads\Autoit-skripte\entwicklung\settings.ini echo %errorlevel% echo %errorlevel% / 100 pause Output is: 0 0 / 100 Did I make anything totally wrong? So long, Mega Ahhhah.... I know what you want now. I was wondering the same thing for my new function and I was also wondering if there was a way to have arguments for the command line. [quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()
greenmachine Posted February 7, 2006 Posted February 7, 2006 I was going to say console functions (read and write primarily), but then I was wondering if it would work to return to the cmd prompt, since I remember reading that AutoIt (or Windows...) disconnects exes from the console. Something like that. I was also going to mention using stdout/stdin functions if you're running a script from another script so that the two scripts can communicate, but it doesn't look like you're doing that. I suppose I don't really have a clue after all, but I have some ideas that you might end up finding useful.
Xenobiologist Posted February 7, 2006 Author Posted February 7, 2006 I was going to say console functions (read and write primarily), but then I was wondering if it would work to return to the cmd prompt, since I remember reading that AutoIt (or Windows...) disconnects exes from the console. Something like that.I was also going to mention using stdout/stdin functions if you're running a script from another script so that the two scripts can communicate, but it doesn't look like you're doing that.I suppose I don't really have a clue after all, but I have some ideas that you might end up finding useful.Thanks, greenmachine. I put a bit more effort in my first script. So, I didn´t need to use the autoit.exe for extracting the version and so on.But after all, I´m still wondring why autoit isn´t able to act like e.g. the find command in DOS. find settings.ini "version" and the result is printed on the DosBox. So what, ... So long,Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
skippynz Posted February 8, 2006 Posted February 8, 2006 isnt the return code of "0" from %errorlevel% just a standard MSDOS Code for success ? ie you got a 0 cause the script was successful. i think if the script failed to run you would probably get a 1 or some other number that would indicate the level of failure ? ie from ms office 1602 is user canceled etc
Xenobiologist Posted February 8, 2006 Author Posted February 8, 2006 isnt the return code of "0" from %errorlevel% just a standard MSDOS Code for success ? ie you got a 0 cause the script was successful. i think if the script failed to run you would probably get a 1 or some other number that would indicate the level of failure ? ie from ms office 1602 is user canceled etcHi,maybe you are right. Then, how I can send and catch another return code of an autoit-script.exe?So long,Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
skippynz Posted February 8, 2006 Posted February 8, 2006 Hi,maybe you are right. Then, how I can send and catch another return code of an autoit-script.exe?So long,Megai just confirmed it - 0 is the script completed without failure, and i just tested by exiting script while at a message box and i then %errorlevel% was now - 9009 think your best bet is either write a registry setting (somewhere that all users can access) or write to a file what you want or need to get back from the second script.
DaveF Posted February 8, 2006 Posted February 8, 2006 Hi, maybe you are right. Then, how I can send and catch another return code of an autoit-script.exe? So long, MegaMHz's example in post #7 of this thread does exactly this, the Exit statement in the AutoIt script sets the errorlevel in the batch file. Your other option is to use ConsoleWrite, which doesn't work properly at a command prompt or in a BAT file (long explanation upon request). If you only have a single line of output you can work around the problem by piping the output of the AutoIt script through SORT.EXE, a-la: REM test.bat start c:\test\test.exe | sort Treat yourself: forget batch files, just use AutoIt... Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.
roy Posted February 9, 2006 Posted February 9, 2006 Hi Mega, in this example there are 2 scripts: Caller.exe (the calling pgm) and Called.exe (the called pgm). This tecnique uses standard input/output streams to talk to/back to the caller/called pgm. Roy. ; CALLER #include <constants.au3> ; How to call an external compiled Autoit script, pass a parameters and get some value back $foo = Run("Called.exe", @ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) StdinWrite($foo, "2"); in the called pgm use ConsoleRead to get this value MsgBox(0, "The Caller", "Value returned from called.exe: " & _ StdoutRead($foo)); in the called pgm use ConsoleWrite to pass a value back Exit ; CALLED ; How to get a value from a calling pgm ; make some calculations and give value back $StdIn = ConsoleRead(); read from standard input stream MsgBox(0, "The Called", "Value received from caller.exe: " & $StdIn) $StdOut = $StdIn * 2 ConsoleWrite($StdOut); write to standard output stream Exit
just_beginner Posted July 29, 2019 Posted July 29, 2019 Hi Xenobiologist, I think I know how to do this, but with LabView as main script to call the autoit script to read a value from one application. 1.In autoit, I use ConsoleWrite to write the value to console that I read using the same script. 2. In LabView I use system exec.vi function to call that autoit script (compiled to exe) and the standard output from the function will return whatever is written by ConsoleWrite in autoit script. Attached is the simple LabView and autoit script to perform as said. I'm not sure how to do this with other language like c# etc. calculator.au3 calculator.exe read_autoit.vi
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now