mtkennerly / shawl

Windows service wrapper for arbitrary commands
MIT License
448 stars 15 forks source link

Weird CWD that makes the application fail #18

Closed gimmi closed 2 years ago

gimmi commented 2 years ago

With this command

.\shawl.exe --help
shawl 1.0.0

.\shawl.exe add --name MyApp --stop-timeout 30000 --restart --cwd . -- MyApp.exe

I get this in Windows service "Path to executable":

C:\Users\dev\Temp\MyApp.win-x64.0.8.1\shawl.exe run --name MyApp --stop-timeout 30000 --restart --cwd \\?\C:\Users\dev\Temp\MyApp.win-x64.0.8.1 -- MyApp.exe

The problem is the weird \\?\ in the cwd parameter, that prevent the app from running appropriately.

gimmi commented 2 years ago

BTW avoinding shawl add command and creating service with the following command works as expected.

sc create MyApp binPath= "C:\Users\dev\Temp\MyApp.win-x64.0.8.1\shawl.exe run --stop-timeout 30000 --restart --cwd C:\Users\dev\Temp\MyApp.win-x64.0.8.1\ -- MyApp.exe"
mtkennerly commented 2 years ago

Hmm, I'm not able to reproduce a failure with this. The \\?\ is just a UNC path prefix, so I'm not sure why it's interfering. Could you share the Shawl logs and/or any logs from your own app to indicate a specific error code?

Here's what I tested:

$ shawl add --name shawl --cwd . -- shawl-child.exe
$ sc start shawl

Path to executable: C:\git\shawl\target\debug\shawl.exe run --name shawl --cwd \\?\C:\git\shawl\target\debug -- shawl-child.exe

shawl_for_shawl_rCURRENT.log shows that shawl-child started successfully:

2022-01-16 23:33:29 [DEBUG] ********** LAUNCH **********
2022-01-16 23:33:29 [DEBUG] Cli { sub: Run { common: CommonOpts { pass: None, restart: false, no_restart: false, restart_if: [], restart_if_not: [], stop_timeout: None, no_log: false, no_log_cmd: false, command: ["shawl-child.exe"], pass_start_args: false }, cwd: Some("\\\\?\\C:\\git\\shawl\\target\\debug"), name: "shawl" } }
2022-01-16 23:33:29 [DEBUG] Entering main service loop
2022-01-16 23:33:29 [INFO] Launching command
2022-01-16 23:33:29 [DEBUG] stderr: "[INFO] ********** LAUNCH **********"
2022-01-16 23:33:29 [DEBUG] stderr: "[INFO] Cli { infinite: false, exit: None, test: false }"
2022-01-16 23:33:29 [DEBUG] stderr: "shawl-child message on stderr"
2022-01-16 23:33:29 [DEBUG] stdout: "shawl-child message on stdout"
2022-01-16 23:33:30 [DEBUG] stderr: "[INFO] Looping!"
2022-01-16 23:33:30 [DEBUG] stderr: "[INFO] Looping!"
2022-01-16 23:33:31 [DEBUG] stderr: "[INFO] Looping!"
mtkennerly commented 2 years ago

I did just find an issue while trying to test this, after I put shawl.exe and shawl-child.exe in different directories, but I'm not sure if it's related to your issue. The CWD technically only applies once the command is running, but Shawl doesn't use the CWD to find the command in order to run it in the first place, so it can't find a relative-style command when the exe is in a different place than Shawl itself. But it looks like you already have shawl.exe in the same place as MyApp.exe, so it might not be related.

mtkennerly commented 2 years ago

I just published v1.1.0, which addresses what I mentioned in my last comment. When you have time, could you please give it a try, in addition to grabbing the log files?

mtkennerly commented 2 years ago

I'm going to close this for now, but if you have a chance to test the new version and there's still an issue, I'd be happy to reopen it.

gimmi commented 2 years ago

Hello,

I did a test with the v1.1.0. The \\?\ is still there in the --cwd parameter, but this time the application works as expected.

So the issue is fixed 👍🏻