ha-bridge icon indicating copy to clipboard operation
ha-bridge copied to clipboard

Executing .bat script Windows

Open DannyTaki opened this issue 2 years ago • 17 comments

I can't figure out from the documentation how I need to format my Target Item field in On Items call. This is what I currently have and I only want to run a script on my local computer. screenshot-localhost-2023 02 13-10_47_59

DannyTaki avatar Feb 13 '23 16:02 DannyTaki

Test it in progressive steps. Start by executing a simple direct command, such as copying a file:

cmd.exe copy c:\test\a.txt c:\test\b.txt

If that doesn't work, try it with the full path to cmd.exe, such as:

c:\windows\system32\cmd.exe copy c:\test\a.txt c:\test\b.txt

If that now works, now retry it as a batch file, with the "copy c:\test\a.txt c:\test\b.txt" command in the copyfile.bat file:

c:\windows\system32\cmd.exe c:\test\copyfile.bat

If that works, try it with your own batch file, etc...

guy1958 avatar Feb 15 '23 15:02 guy1958

How does the HA-Bridge know what device to target on my network to run these commands? I can give me devices a static IP through my router, but where in HA-bridge do I configure this?

DannyTaki avatar Feb 15 '23 15:02 DannyTaki

Well by nature, a "command line" will always be a local command, on the same device that habridge is running on. If you can run a local command that then executes a batch file that can do something over the network (such as curl) then fine , but the command line itself is local.

guy1958 avatar Feb 15 '23 16:02 guy1958

Okay, then it seems to be not working I tried just running cmd.exe copy c:\test\a.txt c:\test\b.txt and even though it was successful when I trigger the device "On" state, it doesn't actually run the command and change the name of the .txt file.

DannyTaki avatar Feb 15 '23 16:02 DannyTaki

image

DannyTaki avatar Feb 15 '23 16:02 DannyTaki

Then you need to start by figuring out why that simple command isn't working. The example I gave you shouldn't change the name of the a.txt file, but copy it to create a b.txt file. You should end up with both files. Make sure you properly create the sample a.txt file, in the proper c:\test path, etc. That's the idea behind this test, to make sure that all paths, etc are good.

guy1958 avatar Feb 15 '23 16:02 guy1958

image

DannyTaki avatar Feb 15 '23 16:02 DannyTaki

If you open a command line window and manually key in:

c:\windows\system32\cmd.exe copy c:\test\a.txt c:\test\b.txt

Does that copy the file?

guy1958 avatar Feb 15 '23 16:02 guy1958

Nope that didn't work hmmm, maybe its not targeting right executable path for the cmd application

DannyTaki avatar Feb 15 '23 17:02 DannyTaki

image

DannyTaki avatar Feb 15 '23 17:02 DannyTaki

image

DannyTaki avatar Feb 15 '23 17:02 DannyTaki

That's what troubleshooting it with simple commands is all about: testing the "plumbing" to see if everything (paths, permissions, etc) is as expected.

Your screen capture of the command line session isn't showing any errors, so the cmd.exe file appears to be in the correct path. In looking at the options for the cmd.exe command, try it with the /c option:

c:\windows\system32\cmd.exe /c copy c:\test\a.txt c:\test\b.txt

This tells cmd.exe to execute the command line, and then exit.

If that works, then try it again but within habridge

guy1958 avatar Feb 15 '23 17:02 guy1958

That worked running the command with the /c option!

DannyTaki avatar Feb 15 '23 17:02 DannyTaki

Oh shit the HA-bridge worked too!!

DannyTaki avatar Feb 15 '23 17:02 DannyTaki

Hehe, the taste of success... Now you can copy files with Alexa voice commands!

So now try it as a batch file. Then replace the copy command in the batch file with your own command, etc.

guy1958 avatar Feb 15 '23 17:02 guy1958

That's awesome, I'm work right now without my Alexa but will test it with Alexa when I'm home. Thank you!

DannyTaki avatar Feb 15 '23 17:02 DannyTaki

For understanding. The Docker Image runs on Windows? How can Ha-Bridge access it?

Multiplexer76 avatar Mar 04 '23 07:03 Multiplexer76