Invoke Powershell error - Java Version

Hi Developers,

I would like to ask why I am keep getting error like this. I am trying to receive a version of Java installed on the machine by simply code “Java -version” in activity “Invoke Powershell”, but instead of the version I got an error. Also, is there a different way how to do this I will be glad if you could share me the details.
image

Best Regards.

Hi @Matej

If you want to invoke the java code in to Ui Path Studio then you can use the Invoke code activity to invoke the java code.

Hope it helps!!

Hi @mkankatala,

unfortunately this is not my case. I need to invoke PowerShell code, “java -version” to be exact.

@Matej
To invoke the PowerShell code java -version in UiPath, you can use the “Invoke PowerShell” activity. Here’s how you can do it:

  1. Drag and drop an “Invoke PowerShell” activity onto your UiPath workflow.
  2. In the Properties panel, locate the “CommandText” property and enter the PowerShell code java -version.
  3. Optionally, you can set the “WorkingDirectory” property to specify the directory where the PowerShell command should be executed. If not set, it will default to the current working directory.
  4. Run your workflow, and the PowerShell code will be executed.

Note that the java -version command is used to check the version of Java installed on your system. If Java is not installed or not configured correctly, this command may not return the desired output. Make sure that Java is installed and the java command is accessible from the command prompt before using it in UiPath.

Additionally, if you need to capture the output of the PowerShell command, you can assign the result to a variable using the “Output” property of the “Invoke PowerShell” activity. This allows you to further process or use the output in your workflow.

Thanks for your reply. I did these steps as you wrote them, but unfortunately the error is still remaining. As you can see on the screenshot the java is installed on the PC, I can access it by command in PowerShell, but when I do this in the code it ends with error.


image

Activate isScript
grafik

Thanks for your reply @ppr. I ticked the IsScript, I got the version of Java, but it’s still in error state as you can see on the screenshot. I also tried with the “Continue on Error”, but in that case I did not get any return.
image

java version vs java -version when the different screenshots are compaired? so the - (hyphen on version) is missmatching?

However as we have seen the isScript was needed

I was trying to run the command with - or without it, so it was just for testing purposes.

it looks like the version info is sent to both streams

  • the ouput stream
  • the error stream

From open jdk we do know the --version

And it’s possible to choose only the output stream? Because as you can see I cannot perform the java --version.
image

give a try with:
--show-version

from the java docs we do see: