Search code examples
javaprocessbuilder

How to execute external application with arguments and receive result


How do i execute external application and pass the arguments and return the result from external application using java #ProcessBuilder and #RunTime ?

public class test {



public static void main(String[] args) {
    try {
        System.out.println("Starting Application");
    //    Runtime runtime =Runtime.getRuntime();

        Process proc= new ProcessBuilder("NconnectLicenseGenerator.exe","ABCDEFGHIJK").start();
        InputStream is = proc.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;
        System.out.printf("Output of the program is %s :" ,Arrays.toString(args));

Here I want to pass the Arguments to my App and submit the arguments through Java and return the results

        while((line=br.readLine())!=null)
        {
            System.out.println(line);
        }

        System.out.println("Closing Application");
    } catch (IOException e) {            
        e.printStackTrace();
    }      
}

}

Solution

  • I have solved this problem by making a console application in .net and using it with java process-builder.