8

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
  • 3,546
  • 5
  • 43
  • 77
Thibault Loison
  • 686
  • 2
  • 6
  • 15
  • 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 Loison 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 Loison Feb 14 '17 at 12:26

1 Answers1

18

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
  • 11,908
  • 2
  • 32
  • 38