这是我来自 jna 示例的代码,我尝试使用 native 代码运行 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
有什么方法可以将上述输出存储在字符串值中
最佳答案
使用 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
关于java - Kernel32.INSTANCE.CreateProcess 返回字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40855891/