Page 1 of 1

Get return status

Posted: 06 Jan 2019, 19:49
by x32
I'm trying to get the return status from a function. Using the code below I get no return.

Code: Select all

USBRelay(serial,oc,chan)
	{
	Run, %comspec% /c CommandApp_USBRelay %serial% %oc% %chan%, , Hide
	Return, %ErrorLevel%
	}
The few instructions for this devices are written by someone who's not too familiar with English. All they say about getting a return value...
If succeed, the command tools will return value 0, else return 1;
The caller can jude the result of execute from the return value.
I can get the return of anything else I try for, while testing I've returned the serial, but I can't figure out how to get the success of the command.

Code: Select all

sn = 4513
oc = open
chan = 1
result := xUSBRelay(sn,oc,chan)
GuiControl, , devsn, %result%
Any ideas? Thanks

Re: Get return status

Posted: 06 Jan 2019, 20:14
by gregster
Perhaps something like this:

Code: Select all

command := "CommandApp_USBRelay " serial " " oc " " chan	; assuming you need spaces between the parameters
msgbox % RunWaitOne(command)

RunWaitOne(command) {
    ; WshShell object: http://msdn.microsoft.com/en-us/library/aew9yb99
    shell := ComObjCreate("WScript.Shell")
    ; Execute a single command via cmd.exe
    exec := shell.Exec(ComSpec " /C " command)
    ; Read and return the command's output
    return exec.StdOut.ReadAll()
}
The RunWaitOne function is from the Run docs (--> Examples) and returns the output of the executed command

Re: Get return status

Posted: 06 Jan 2019, 20:42
by x32
Thanks but this one is still not returning anything and it doesn't activate the relay I'm controlling. I'm still playing around with it but I can't figure out how to make it work with the relay.

Re: Get return status

Posted: 06 Jan 2019, 20:54
by gregster
Do you get something back if you use CommandApp_USBRelay... directly from the command line (just for testing)?

Re: Get return status

Posted: 07 Jan 2019, 09:10
by x32
Did not get anything back but it did work with the relay this way. Of course this is way over my head so I am likely am not doing it right.

This script controls the relay but the message box is blank.

Code: Select all

Gui, Add, Button, x5 y5 w100 h25 voff goff, Off
Gui, Add, Button, x+5 y5 w100 h25 von gon, On

Gui, Show,  w220 h50 ,  
Return

off:
serial = D-V
oc = close
chan = 1
command := "CommandApp_USBRelay " serial " " oc " " chan	
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec(ComSpec " /C " command)
msgbox % exec.StdOut.ReadAll()
Return

on:
serial = D-V
oc = open
chan = 1
command := "CommandApp_USBRelay " serial " " oc " " chan	
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec(ComSpec " /C " command)
msgbox % exec.StdOut.ReadAll()
Return

Re: Get return status

Posted: 07 Jan 2019, 12:17
by Frosti
You can read information by using the normal command shell in windows?

Re: Get return status

Posted: 07 Jan 2019, 16:16
by x32
Frosti wrote:
07 Jan 2019, 12:17
You can read information by using the normal command shell in windows?
Not sure how to do that.

Re: Get return status

Posted: 07 Jan 2019, 19:28
by Frosti
I mean with your eyes! Have you tried it here?
Image

Re: Get return status

Posted: 07 Jan 2019, 20:02
by x32
I don't know how to get return info from a cmd prompt. I can control the relay with it but not get any success/fail info.

Re: Get return status

Posted: 08 Jan 2019, 06:24
by Frosti
There's no visible return on command prompt? It's the same question like gregsters questions before.