0

I am using PowerShell script to start a Java application.

$app = Start-Process -FilePath java -ArgumentList "-jar $path_to_jar" -PassThru

OR

java -jar $path_to_jar

When I am running this script, in PowerShell Core it's executing properly , but if I run the same script in normal PowerShell (Windows PowerShell) - it's giving error "Unable to access jarfile"

Even if I run PowerShell (Windows PowerShell) with Admin privilege getting same result, whereas PowerShell Core working without Admin Privileges

Any help is appreciated.

Posto
  • 7,362
  • 7
  • 44
  • 61
  • 1
    Does `$path_to_jar` contain a relative or absolute path? Windows PowerShell does not update the process working directory when you change location with `cd`/`{Set,Push,Pop}-Location`, so relative paths passed to executables (like `java.exe`) might resolve differently – Mathias R. Jessen Feb 04 '22 at 09:55
  • @MathiasR.Jessen - seems like this is the issue - JAR path causing this issue – Posto Feb 04 '22 at 13:09
  • 1
    Try calling `[environment]::CurrentDirectory = $PWD` right before invoking java in Windows PowerShell – Mathias R. Jessen Feb 04 '22 at 13:11
  • Thanks @MathiasR.Jessen - it solved my issue. – Posto Feb 04 '22 at 13:36

0 Answers0