Powershell process hanging when called from a Java application

I am trying to write a simple application that takes a command line argument (which will be a Powershell pss file) and then run it. So I tried a number of different approaches and seemed to run into a problem. If I try to call powershell from java, the windows process starts and displays through the process explorer, however powershell never returns, it hangs in some loop in appearance. The command I use is:

            String command = "powershell -noprofile -noninteractive \"&C:\\new\\tst.ps1\"";

Then the command is executed with:

Runtime systemRuntime = Runtime.getRuntime();
Process proc = systemRuntime.exec(command);

I am currently hard-coded the location to the ps1 file as I was trying to eliminate this due to a problem. Using the process explorer, I see the hanging powershell process, and the command that was passed to it was:

powershell -noprofile -noninteractive "&C:\new\tst.ps1"

cmd- , tst.ps1. , , - , ps1. .

, java, , powershell , .

- , , , , , , .

/ : D

+5
2

OutputStream, PowerShell .

Runtime systemRuntime = Runtime.getRuntime();
Process proc = systemRuntime.exec(command);

proc.getOutputStream().close();
+8

(err out)? , , , java. InputStreams,

Process.getInputStream()

Process.getErrorStream()

: Javadoc

+2

All Articles