Start process in nohup detached mode

New to Powershell!

I have tried to create a start script that:

  • Setup environment
  • read a dictionary file (what processes I should start, and there parameters)

Today I’m trying to start the above processes using:

$process = Start-Process -FilePath "cmd.exe" -ArgumentList "/c", "${startCmdEval} > `"$logPath`" 2>&1" -NoNewWindow -PassThru

Or even more basic:

Start-Process 'java' '-cp classes\ com.gorans.SleepServer -Sqwerty' -NoNewWindow -PassThru -RedirectStandardOutput xxx.console -RedirectStandardError xxx.console.2

The above works, fine, BUT when I exit the Terminal/DOS window, the processes stops

I’m used to Linux, and here is what I do from a Shell script, which works just fine!

echo " * Starting monitoring of server '${srvName}' ${withAliasDesc} (with nohup in background, output to ${dbxCentralBase}/log/${srvNameOrAlias}.console)."
nohup ${startCmdEval} > ${dbxCentralBase}/log/${srvNameOrAlias}.console 2>&1 &

nohupnohup - Wikipedia

How do I accomplish this in PowerShell ???
I have spent a lot of time to figure out how to do it without success!

Any help would be appreciated

And you tried google ???

Yes I have tried:
java -cp classes\ com.gorans.SleepServer -Sqwerty > xxx.console 2>&1 &

Or (which is in above example):
Start-Process ... -NoNewWindow

The problem is not the background, It’s that: sub processes dies then terminating the parent process
I still want my processes to continue running after the user logs out (or terminates the shell/terminal)

So it’s more the nohup functionality that I’m looking for…

Looks like Start-Process with WindowStyle Hidden might be worth a shot. Scroll down a bit to see the “Windows” solution.

The -WindowStyle Hidden woked a bit on the way…
I can terminate the parent process (the DOS/Terminal) that started it!

BUT: Still when I logout the process i terminated
So half way there!

I still need the started process to continue running after I logout.

Any more ideas :slight_smile:

AFAIK that does not work on Windows. Either you configure your system to run your command line as the local “SYSTEM” or another dedicated local or domain account by using the task scheduler or you create a service to run in the background.

Running something in a Windows machine without beeing logged on needs the permission for the account to log on as batch job.