Command output as string

Posted by rik on Super User See other posts from Super User or by rik
Published on 2012-06-29T21:01:58Z Indexed on 2012/06/29 21:18 UTC
Read the original article Hit count: 228

Filed under:

I want to get output from command C:\Program Files (x86)\Java\jre7\bin\java.exe" -version as string variable.

I tried this way: $out = &"C:\Program Files (x86)\Java\jre7\bin\java.exe" -version

but it gives error message:

java.exe : java version "1.7.0_05"
At line:1 char:9
+ $out = & <<<< "C:\Program Files (x86)\Java\jre7\bin\java.exe" -version
    + CategoryInfo          : NotSpecified: (java version "1.7.0_05":String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Java(TM) SE Runtime Environment (build 1.7.0_05-b05)


Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode, sharing)

$out variable seems empty.

What am I doing wrong?

© Super User or respective owner

Related posts about powershell