Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用参数执行外部应用程序并接收结果_Java_Processbuilder - Fatal编程技术网

Java 如何使用参数执行外部应用程序并接收结果

Java 如何使用参数执行外部应用程序并接收结果,java,processbuilder,Java,Processbuilder,如何使用java#ProcessBuilder和#RunTime执行外部应用程序并传递参数并从外部应用程序返回结果 public class test { public static void main(String[] args) { try { System.out.println("Starting Application"); // Runtime runtime =Runtime.getRuntime(); Process

如何使用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();
    }      
}

}

您可以在此处找到如何向Java应用程序发送命令行参数:

对于用Java调用外部程序:
Process proc=new ProcessBuilder(“NconnectLicenseGenerator.exe”,String.join(“,args.start())

我在.net中创建了一个控制台应用程序,并将其与java process builder一起使用,从而解决了这个问题。

实际上,我在其中传递参数的应用程序是.net应用程序,我尝试了这个,它仍然不起作用,你能帮我吗?@Pranay Chandale,请删除java标记,添加我需要控制.net应用程序的C#Bro使用Java请帮助我查找您的问题。是在尝试获取NconnectLicenseGenerator.exe的标准输出时发生的?还是由于对NconnectLicenseGenerator.exe的调用不正确造成的?您是否有权访问NconnectLicenseGenerator.exe的源代码?