function getOutput { $size = 4096 $outBuf = New-Object System.Char[] $size foreach ($stream in $args) { if ($stream -eq $null) { continue } while (-1 -ne $stream.Peek()) { $length = $stream.Read($outBuf, 0, $size) if ($length -lt 1) { break } $str = ($outBuf[0..($length-1)] -join "").ToString().Trim() write-host -ForegroundColor green "> $str" } break } } $p = New-Object System.Diagnostics.Process $p.StartInfo.RedirectStandardOutput=$true #$p.StartInfo.RedirectStandardError=$true $p.StartInfo.RedirectStandardInput=$true $p.StartInfo.UseShellExecute=$false $p.StartInfo.CreateNoWindow=$true $p.StartInfo.Arguments="-Djava.library.path=""\lib\*;"" -classpath ""\lib\*;"" com.aris.prov.macc.MultiAgentCommandLineCloudController -u userName -pwd passWord -h localhost -p 12345" $p.StartInfo.FileName="""C:\...\bin\JAVA.EXE""" if (!$p.Start()) { exit } $out = $p.StandardOutput $err = $p.StandardError clear $global:ver++ write-host -ForegroundColor gray "Version $ver" getOutput($out) sleep -milli 1000 #write-host -ForegroundColor yellow "Attempting to stopall..." # #$p.StandardInput.WriteLine("stopall") #$p.StandardInput.Flush() # #write-host -ForegroundColor yellow "Attempted to stopall..." # #getOutput($out) # #sleep -milli 10000 #write-host -ForegroundColor yellow "Attempting to startall..." # #$p.StandardInput.WriteLine("startall") #$p.StandardInput.Flush() # #write-host -ForegroundColor yellow "Attempted to startall..." # #getOutput($out) # #sleep -milli 10000 write-host -ForegroundColor yellow "Attempting to list..." $p.StandardInput.WriteLine("list") $p.StandardInput.Flush() write-host -ForegroundColor yellow "Attempted to list..." getOutput($out) sleep -milli 1000 write-host -ForegroundColor yellow "Attempting to exit..." $p.StandardInput.WriteLine("exit") $p.StandardInput.Flush() write-host -ForegroundColor yellow "Attempted to exit..." getOutput($out) sleep -milli 1000 $p.WaitForExit() $p.Close()