How to call a Java program from PowerShell?

I need to call a java program (jar file) from PowerShell. The following code works:

java -jar $cls --js $dcn --js_output_file $dco

But I need to run the application in the process (using Start-Process).

I am trying to do the following without sucess:

Start-Process -FilePath java -jar $cls --js $dcn --js_output_file $dco -wait -windowstyle Normal

Error:

Start-Process : A parameter cannot be found that matches parameter name 'jar'.

Any idea how to fix this?

+8
source share
2 answers

You will need to use the following format for powershell:

 Start-Process java -ArgumentList '-jar', 'MyProgram.jar' '
-RedirectStandardOutput '.\console.out' -RedirectStandardError '.\console.err' 

Or another option you can use: Start-job:

Start-Job -ScriptBlock {
  & java -jar MyProgram.jar >console.out 2>console.err
}
+10
source

It seems that it is -jarperceived as an argument Start-Process, and does not go to java.

, -ArgumentList , , -option -type.

, :

Start-Process -FilePath java -ArgumentList ...

, PowerShell ISE Java ( ):

Start-Process -FilePath java -argumentlist -help

:

Start-Process -FilePath java -help

Powershell -help.

0

All Articles