Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

How to start a proccess and execute a specific command in it?

$
0
0
I need to start a process (java server) with powershell and then be able to execute a specific command inside the context of the started process/server. For context, if I start the server normaly I then get a console window where I can enter different commands like status, stop etc. But of course they only work inside the server process and not in powershell.

So how can I start a process with powershell, let it run and access/send commands to that process later?

Here is what I have tried so far:

$SERVER_JAR = "myServer.jar"
$MIN_RAM = "1024M"
$MAX_RAM = "5G"

$javaArgs = @('-server', "-Xms$($MIN_RAM)", "-Xmx$($MAX_RAM)", "-jar $SERVER_JAR", 'nogui') # some arguments for the java process

Start-Process java -ArgumentList $javaArgs -NoNewWindow -Wait # starting the java server process in the same window/process

if (condition) {
    stop # This specific stop command should be executed inside the java server process, because it does ensure the server is saved etc. before shutdown
}


Viewing all articles
Browse latest Browse all 2314