Sign in to follow this  
Followers 0
alex146089

function return need help

6 posts in this topic

how i can get return value from compiled "function"???

if i run not compiled script then i can use "function" return value in other script

if i compile and run---i get nothing...

how to make my compiled script to redirect function return value to stdout???

sorry for my english...

for example...

Global $mySusRet

$i_PID=1238 ;for exemple

ae_suspend_process($i_PID)

func ae_suspend_process($i_PID = -1)

If $i_PID <> -1 Then

Dim $s_TempFile

Dim $aRecords

$s_TempFile = _TempFile()

$foo=Run(@ComSpec & " /c " & 'pssuspend' & ' ' & $i_PID ,"",@SW_HIDE,$STDOUT_CHILD)

While 1

$line = StdoutRead($foo)

If @error = -1 Then ExitLoop

FileWrite($s_TempFile,$line)

Wend

_FileReadToArray($s_TempFile,$aRecords)

FileDelete($s_TempFile)

if $aRecords[7]="Process does not exist." Then

$mySusRet=$aRecords[7]

Else

$mySusRet=$aRecords[6]

EndIf

EndIf

Return $mySusRet

EndFunc ;==>_suspend_process

i get the result in "var"-> $mySusRet <- and can use this "var" in other scripts

but if i run a compiled version of this cod i get nothing on stdout of this executable...

helpppppp.... :whistle:

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The Exit instruction will allow you to specify a return code in integer form, which can be used in your other script like this:

$returnCode = runWait("compiledScript.exe")
; (and then process the return code)

Edit: So to match your example, you would change this code:

; ···
; ae_suspend_process($i_PID)
$value = ae_suspend_process($i_PID)
exit $value
; ···

P.S. Please post support questions in the Support forum! :whistle:

Edited by LxP

Share this post


Link to post
Share on other sites

thank you for your reply :whistle:

but it will return integer like 0 or 1 or something else

but i need a contents of that variable not an integer :dance:

Share this post


Link to post
Share on other sites

As processes can only return integers when they exit, you may wish to look at writing your value to a temporary file or the registry. Your other script could then read this value by checking the appropriate location.

Please refer to the AutoIt help file for information on commands such as RegWrite(), RegRead(), INIWrite() and INIRead(). Good luck!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The ConsoleWrite function writes a string to STDOUT, so

ConsoleWrite($mySusRet)

...should do what you wish.

Be warned that compiled AutoIt scripts are not considered console applications by Windows. If you run your compiled script by itself in a DOS window you'll see no output because the Windows shell disconnects the STDOUT pipe from non-console applications when they are spawned.

When your compiled script is started in some other manner than the Windows shell then the output will be available as expected.

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Edit: Does this imply that one AutoIt script could read another AutoIt script's ConsoleWrite() output with StdOutRead()? Perhaps this clarification should be documented in the Function Reference.

Edit: Yes, in fact that's precisely what Dave was saying: :whistle:

consoleWrite("This is my return value.")

$pid = run("Script1.exe", "", "", 2)

processWaitClose($pid)

msgBox(0x40, "Script1 Return Value", stdOutRead($pid))

Edit: I would like to suggest that the ConsoleWrite() documentation should be somewhat enhanced to include the above information, i.e. 'ConsoleWrite() writes to STDOUT and can therefore be used to communicate with processes that call it. It functions in the same way as a console print in that a compiled AutoIt script can be called thus:

C:\Scripts>CompiledScript.exe > ConsoleWriteOutput.txt

C:\Scripts>Type ConsoleWriteOutput.txt
This output is generated via calls to ConsoleWrite().
C:\Scripts>

however it cannot be used to visibly print to the console:

C:\Scripts>CompiledScript.exe

C:\Scripts>

Popular text editors can read and display information sent via ConsoleWrite() if the editor is used to invoke the script.

' Edited by LxP

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