Kernel32.INSTANCE.CreateProcess返回String

时间:2016-11-29 00:31:42

标签: java jna

以下是jna示例中的代码我尝试使用本机代码运行cmd命令

boolean status = Kernel32.INSTANCE.CreateProcess(
                    null,
                    "cmd.exe /c echo here is output",
                    null,
                    null,
                    true,
                    new WinDef.DWORD(0),
                    Pointer.NULL,
                    System.getProperty("java.io.tmpdir"),
                    startupInfo,
                    processInformation);

当我运行代码时,我在编译器中得到了这个

here is output

是否可以将Above Output存储为字符串值

1 个答案:

答案 0 :(得分:2)

使用来自Apache Commons Exec

的代码How can I capture the output of a command as a String with Commons Exec?,您可以更轻松地完成此操作

如果由于某种原因需要专门使用JNA,可以使用@KompjoeFriek发布的内容 - how to get the process output when using jna and CreateProcessW

相关问题