How do I use the IF
command to respond on the output of the first java relay status command.
When you run the command the output is 0 when relay 1 is off. example below.
java -jar "C:\4_USB_Relay\DenkoviRelayCommandLineTool_10.jar" DAE001DQ 4 1 status
0
*REM Check_relay_status_output*
java -jar "C:\4_USB_Relay\DenkoviRelayCommandLineTool_10.jar" DAE001DQ 4 1 status
*REM Turn_relay_on*
java -jar "C:\4_USB_Relay\DenkoviRelayCommandLineTool_10.jar" DAE001DQ 4 1 1
*REM Turn_relay_off*
java -jar "C:\4_USB_Relay\DenkoviRelayCommandLineTool_10.jar" DAE001DQ 4 1 0
My idea is to use the one batch script to turn a relay on when its off and off when its on. :)
I'm not sure how to do this as its using a java command and I'm not sure how to capture the output.
All help would be greatly appreciated. :)
does this set errorlevel or the result is just printed? You can use FIND command and conditional execution :
java -jar "C:\4_USB_Relay\DenkoviRelayCommandLineTool_10.jar" DAE001DQ 4 1 status 2>&1 | find "0" && (
java -jar "C:\4_USB_Relay\DenkoviRelayCommandLineTool_10.jar" DAE001DQ 4 1 1
) || (
java -jar "C:\4_USB_Relay\DenkoviRelayCommandLineTool_10.jar" DAE001DQ 4 1 0
)
You can use System.exit(int)
in your Java process to set a return code for the batch script. Then, in your batch script you can get the return code as ERRORLEVEL
like
echo %ERRORLEVEL%
And an if
might look like
IF %ERRORLEVEL% EQU 0 echo Zero
IF %ERRORLEVEL% EQU 1 echo One
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.