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.

4
  • 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 Commented Feb 4, 2022 at 9:55
  • @MathiasR.Jessen - seems like this is the issue - JAR path causing this issue Commented Feb 4, 2022 at 13:09
  • 1
    Try calling [environment]::CurrentDirectory = $PWD right before invoking java in Windows PowerShell Commented Feb 4, 2022 at 13:11
  • Thanks @MathiasR.Jessen - it solved my issue. Commented Feb 4, 2022 at 13:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.