I am trying to store a command prompt command to a variable in Powershell, as well as outputting it to a file. Since the command has 3 lines of output, nothing gets stored as a variable or written to file. The only thing that happens when I attempt to store or output to file, is that the output gets printed to the screen.
input:
java -version
output:
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b25)
Java HotSpot(TM) Client VM (build 25.251-b25, mixed mode)
I have tried the following which did not work:
$variable = (java -version)
$variable = cmd /c "java -version")
java -version | out-file test.txt
