Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing .bat script Windows #1385

Open
DannyTaki opened this issue Feb 13, 2023 · 17 comments
Open

Executing .bat script Windows #1385

DannyTaki opened this issue Feb 13, 2023 · 17 comments

Comments

@DannyTaki
Copy link

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

@guy1958
Copy link

guy1958 commented Feb 15, 2023

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

@DannyTaki
Copy link
Author

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?

@guy1958
Copy link

guy1958 commented Feb 15, 2023

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.

@DannyTaki
Copy link
Author

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
Copy link
Author

image

@guy1958
Copy link

guy1958 commented Feb 15, 2023

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.

@DannyTaki
Copy link
Author

image

@guy1958
Copy link

guy1958 commented Feb 15, 2023

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?

@DannyTaki
Copy link
Author

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

@DannyTaki
Copy link
Author

image

@DannyTaki
Copy link
Author

image

@guy1958
Copy link

guy1958 commented Feb 15, 2023

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

@DannyTaki
Copy link
Author

That worked running the command with the /c option!

@DannyTaki
Copy link
Author

Oh shit the HA-bridge worked too!!

@guy1958
Copy link

guy1958 commented Feb 15, 2023

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.

@DannyTaki
Copy link
Author

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

@Multiplexer76
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants