You can use JNA . With version 3.3.0 or later of CreateProcess :
WinBase.PROCESS_INFORMATION.ByReference processInfo = new WinBase.PROCESS_INFORMATION.ByReference(); WinBase.STARTUPINFO startupInfo = new WinBase.STARTUPINFO(); String command = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + "-noframemerging \"C:\\\u65E5\u672C\u8A9E\\Main.html\""; if (!Kernel32.INSTANCE.CreateProcess( null, // Application name, not needed if supplied in command line command, // Command line null, // Process security attributes null, // Thread security attributes true, // Inherit handles 0, // Creation flags null, // Environment null, // Directory startupInfo, processInfo)) { throw new IllegalStateException("Error creating process. Last error: " + Kernel32.INSTANCE.GetLastError()); } // The CreateProcess documentation indicates that it is very important to // close the returned handles Kernel32.INSTANCE.CloseHandle(processInfo.hThread); Kernel32.INSTANCE.CloseHandle(processInfo.hProcess); long pid = processInfo.dwProcessId.longValue();
Redirecting output from a child process is a bit more complicated, but not impossible.
Luke quinane
source share