10

I've tried the following:

Start-Process powershell -ArgumentList "C:\Program Files\Prometheus.io\prometheus.exe" -WindowStyle hidden
Invoke-Command -ComputerName . -AsJob -ScriptBlock {
    'C:\Program Files\Prometheus.io\prometheus.exe'
}
Start-Job -Name "prometheus" -ScriptBlock {Get-Process prometheus.io}
Start-Job {& .\prometheus.exe}

Sometimes it starts but terminates immediately after starting. If I start it manually it works correctly.

How can I keep my process alive in background?


EDIT :

It doesn't worked because i wasn't in the directory of my process that need a file which pathfile is not set.

Martin Schröder
  • 4,176
  • 7
  • 47
  • 81
Thibault
  • 842
  • 2
  • 8
  • 16
  • 1
    Your syntax for Start-Process is wrong, you don't need to reference powershell, just launch your program with the WindowStyle param set like this: `Start-Process "C:\Program Files\Prometheus.io\prometheus.exe" -WindowStyle Hidden` – henrycarteruk Feb 14 '17 at 10:34
  • It doesn't work, my process stop right away... – Thibault Feb 14 '17 at 12:19
  • Nevermind it doesn't worked because I wasn't in the directory and my process can't start correctly because he have a default argument that must be changed if i'm not in the directory. Thanks ! – Thibault Feb 14 '17 at 12:26

1 Answers1

19

Your syntax for Start-Process is wrong, you don't need to reference powershell, just launch your program with the WindowStyle param set

Start-Process "C:\Program Files\Prometheus.io\prometheus.exe" -WindowStyle Hidden

The WorkingDirectory param can also be used to start the program in a specific directory

Start-Process "C:\Program Files\Prometheus.io\prometheus.exe" -WorkingDirectory "C:\Program Files\Prometheus.io" -WindowStyle Hidden
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • Does this allow you to close the terminal you run this command in AND still have the process running, or is it tied to the terminal you run this in? – conterio Sep 17 '22 at 21:49