brettwooldridge / NuProcess

Low-overhead, non-blocking I/O, external Process implementation for Java
Apache License 2.0
710 stars 84 forks source link

Executing a bat in Windows with spaces #154

Closed j3rem1e closed 5 months ago

j3rem1e commented 5 months ago

I'm trying to launch a .bat in windows in a folder containing spaces.

What I want to start is a command like :

cmd.exe /c ""C:\Program Files\MyApp\start.bat" "another args with spaces""

However, nuprocess seems to quote the double quote inside the 3rd args and my command fails. Is it possible to launch such command line or what I am doing wrong ?

bturner commented 5 months ago

@j3rem1e,

Quote handling on Windows has a lot of edge cases, and it looks like the way cmd /c wants to handle subsequent arguments is tripping up NuProcess's quoting helper. I won't lie; trying to change the logic in WindowsCreateProcessEscape makes me nervous, because it doesn't have good test coverage and it's so easy to regress handling for other edge cases.

With that said, is there a reason you need cmd /c? new NuProcessBuilder(Arrays.asList("C:\\Program Files\\MyApp\\start.bat", "another args with spaces")) should be able to run your batch file without it. Have you tried it that way to see if it works?

j3rem1e commented 5 months ago

Ok thanks, you're right, it works without the "cmd.exe /c" 😄 I'm not a windows export, and I used to use cmd.exe to launch bat files. I didn't know that createprocess accepts bat file.