使用process builder调用exe并通过代码传递值

jecbmhm3  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(206)

下面是源代码

Scanner myObj = new Scanner(System.in);
        String name = args[0];
        if (name.contains("hello")) {
            System.out.print("Enter another name : ");
            name = myObj.nextLine();
        } else {
            System.out.println(name);
        }
        System.out.println("Entered name : " + name);

调用jar文件的processbuilder代码。但不知道如何传递值?

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "C:\\Temp\\TestJar.jar", "hello");
        pb.redirectErrorStream(true); // redirect error stream to output stream
        pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
        Process proc = pb.start();

        System.out.println("Job running");
        proc.waitFor();
        System.out.println("Job finished");

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题