PrOgrAMmer PrOgrAMmer - 7 days ago 6
Java Question

Kernel32.INSTANCE.CreateProcess return as String

Here is my code from the jna sample i am try using native code to run cmd command

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);


When i run the code i got this in the Compiler

here is output


Is any way to store the Above Output in a string value

Answer

You're going to have a much easier time doing this with Apache Commons Exec with the code from How can I capture the output of a command as a String with Commons Exec?

If you need to specifically use JNA for some reason, you can use what @KompjoeFriek posted -- how to get the process output when using jna and CreateProcessW

Comments