how to get the process output when using jna and CreateProcessW
-
29-10-2019 - |
سؤال
I'm trying to figure out how to read the standard out/err from the process I've created with CreateProcessW. I looked at the docs, googled and searched this list but I didn't find good pointers/samples yet :)
Here's what I came up with so far (it's working fine on windows, it's a relevant snippet from my java code):
Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
Kernel32.StartupInfo startupInfo = new Kernel32.StartupInfo();
Kernel32.ProcessInfo processInformation = new Kernel32.ProcessInfo();
if (!kernel32.CreateProcessW(null, new WString(command), null, null, false,
DETACHED_PROCESS, null, new WString(dir.getAbsolutePath()), startupInfo,
processInformation)) {
throw new IOException("Could not start process. Errno: " +
kernel32.GetLastError());
}
kernel32.CloseHandle(processInformation.hProcess);
kernel32.CloseHandle(processInformation.hThread);
So... how can I grab the output from that process? Anyone has done that already and care sharing a sample?
Thanks guys for any help in advance.
لا يوجد حل صحيح
لا تنتمي إلى StackOverflow