Get return status

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Get return status

06 Jan 2019, 19:49

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
gregster
Posts: 8992
Joined: 30 Sep 2013, 06:48

Re: Get return status

06 Jan 2019, 20:14

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
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Get return status

06 Jan 2019, 20:42

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.
gregster
Posts: 8992
Joined: 30 Sep 2013, 06:48

Re: Get return status

06 Jan 2019, 20:54

Do you get something back if you use CommandApp_USBRelay... directly from the command line (just for testing)?
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Get return status

07 Jan 2019, 09:10

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
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Get return status

07 Jan 2019, 12:17

You can read information by using the normal command shell in windows?
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Get return status

07 Jan 2019, 16:16

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.
x32
Posts: 177
Joined: 25 Nov 2016, 16:44

Re: Get return status

07 Jan 2019, 20:02

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.
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Get return status

08 Jan 2019, 06:24

There's no visible return on command prompt? It's the same question like gregsters questions before.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, OrangeCat and 81 guests