-3

I trying to call a a java application from powershell but I am not exactly sure how to do this.

to keep it simple. I have a a java file called HelloWorld.java that looks like the following'

public class HelloWorld
{
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Now assume I have compiled this code and I now have a file called HellowWorld.class

I can run this application from a bat file called HelloWorld.bat and it runs just fine. the HelloWorld.bat file has one line

"C:\Program Files\Java\jdk1.8.0_191"\bin\java.exe -cp ; HelloWorld

I am not 100% sure how I would call this java application directly from powershell. Now, before someone says just use

& HelloWorld.bat

Note that the above is an example. The java app that I want to call has parameters and the powershell app will be processing data to determine what parameter values to pass to the java script.

I have tried a number of things but no success. Any help would be appreciated.

  • 1
    side note: you can pass arguments to batch file and batch file can pass them to java – Iłya Bursov Dec 30 '19 at 18:13
  • 1
    Does this answer your question? [Executing an EXE file using a PowerShell script](https://stackoverflow.com/questions/4639894/executing-an-exe-file-using-a-powershell-script) – Iłya Bursov Dec 30 '19 at 18:14
  • Are you looking for [Start-Process](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-6)? – Slaw Dec 30 '19 at 22:41
  • Note that I tried to use Start-Process but had no success at getting this function to work. – Robert R Jan 02 '20 at 13:22

1 Answers1

0

you can use below command to execute the batch file with arguments

& .\HelloWorld.bat parm1
dassum
  • 4,727
  • 2
  • 25
  • 38
  • Passing params to a .bat file would work, was hoping to do away with an additional file but that would work. – Robert R Dec 30 '19 at 18:51