Closed mlenz968 closed 1 year ago
shawl add --name PS_Test -- "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File service_master.ps1"
There are a couple of problems with this command:
service_master.ps1
is a relative path, but you haven't specified a --cwd
, so it'll look for the script in whatever default working directory Windows assigns to the service. You probably want to either set --cwd
or use an absolute path to the script.For example, if the script is in C:\scripts\service_master.ps1
, then you could try one of these:
shawl add --name PS_Test -- powershell -File C:\scripts\service_master.ps1
shawl add --name PS_Test --cwd C:\scripts -- powershell -File service_master.ps1
I also tried the following variants but they all had the same problem:
shawl add --name PS_Test --cwd "C:\service_test" -- powershell -File "service-master.ps1"
shawl add --name PS_Test --cwd C:\service_test -- powershell -File service-master.ps1
shawl add --name PS_Test -- powershell -File "C:\service_test\service-master.ps1"
shawl add --name PS_Test -- powershell -File C:\service_test\service-master.ps1
If I put the powershell -File C:\service_test\service-master.ps1
into a service-master.cmd
and register the service via shawl add --name PS_Test -- C:\service_test\service-master.cmd
the service registration is ok.
Also the graceful shutdown of my application via ctrl-c works.
The only drawback is that after the graceful shutdown of the app the script does not terminate because the command interpreter waits for the "Terminate batch job (Y/N)" confirmation.
I made another test.
I created a symbolic link to powershell mklink ps.exe C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
and used ps.exe in the command. This time everything is ok.
But if I use powershell.exe as link name then I have the same problems as before.
That's really strange.
But at least I have a workaround for this problem.
Yeah, that's really weird. Unfortunately, I'm not able to reproduce it. This worked for me on Windows 11 with PowerShell 5.1.22621.1778:
Add-Content script.txt "`ntest"
shawl.exe add --name PS_Test --cwd C:\tmp -- powershell -File script.ps1
sc start PS_Test
test
What happens if you try using the same test script?
I was also able to just do shawl.exe add --name PS_Test --cwd C:\tmp -- script.ps1
without specifically referencing powershell
. Does that work for you, so you can avoid the symbolic link?
I want to start a powershell script with shawl but as soon as I have powershell on the shawl command line the Windows service is broken. Of course my original service registration has more arguments but I could reduce it to this simple service registration to reproduce the problem:
shawl add --name PS_Test -- "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File service_master.ps1"
or evenshawl add --name PS_Test -- powershell -File service_master.ps1
If I try to open the service properties in the Windows Services I get an error message
The system cannot find the file specified.
Also the service description only contains an error message:
<Failed to Read Description. Error Code: 2 >
Does anybody have an idea what could be the root cause and how to solve it?