引数を指定して、外部アプリケーションを実行し、結果を受信する方法

Pranay Chandale:

どのように私は、外部アプリケーションを実行し、引数を渡すと、Javaの#ProcessBuilderと#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));

ここで私は私のアプリに引数を渡すとJavaによる引数を提出し、その結果を返すようにしたいです

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

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

}
Pranay Chandale:

私は.NETでコンソールアプリケーションを作成し、Javaプロセスビルダーでそれを使用することによって、この問題を解決しました。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=313583&siteId=1