'How to migrate a bash script to run in windows .ps1 as a service?
I am using winsw (see https://github.com/winsw/winsw) to run a ps1 file as a service in Windows 10. I need to run a bash script in that service.
I was hoping that I could execute a bash script in that .ps1 file just like I normally would in powershell, but the result is no stdout is produced in this case. Here is an example of my service file.
Write-Host "Test Service"
$ErrorActionPreference = "Stop"
$Timer = New-Object Timers.Timer
$Timer.Interval = 10000
$Timer.Enabled = $True
$Timer.AutoReset = $True
$objectEventArgs = @{
InputObject = $Timer
EventName = 'Elapsed'
SourceIdentifier = 'myservicejob'
Action = {
$ErrorActionPreference = "Stop"
Write-Host "Run bash script"
bash /mnt/c/AppData/my-bash-script
Write-Host "Finished running bash script"
}
}
$Job = Register-ObjectEvent @objectEventArgs
Wait-Event
For the bash script (my-bash-script), a simple echo command will reproduce the problem:
#!/bin/bash
echo "my test"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
