Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run exe in background

Tags:

powershell

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.

like image 332
Thibault Loison Avatar asked Feb 14 '17 09:02

Thibault Loison


1 Answers

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
like image 93
henrycarteruk Avatar answered Oct 24 '22 00:10

henrycarteruk