Search in sources :

Example 1 with STARTUPINFO

use of jnc.platform.win32.STARTUPINFO in project judge by zjnu-acm.

the class WindowsExecutor method createProcess.

private PROCESS_INFORMATION createProcess(String lpCommandLine, long hIn, long hOut, long hErr, boolean redirectErrorStream, Path lpCurrentDirectory) {
    STARTUPINFO startupInfo = new STARTUPINFO();
    startupInfo.setCb(startupInfo.size());
    startupInfo.setDesktop(DESKTOP);
    PROCESS_INFORMATION lpProcessInformation = new PROCESS_INFORMATION();
    // without cursor feed back
    startupInfo.setFlags(STARTF_USESTDHANDLES | STARTF_FORCEOFFFEEDBACK);
    startupInfo.setStdInput(hIn);
    startupInfo.setStdOutput(hOut);
    startupInfo.setStdError(hErr);
    setInheritable(hIn);
    setInheritable(hOut);
    if (!redirectErrorStream) {
        setInheritable(hErr);
    }
    try {
        ProcessCreationHelper.execute(() -> {
            String lpApplicationName = null;
            int dwCreationFlags = CREATE_SUSPENDED | DETACHED_PROCESS | HIGH_PRIORITY_CLASS | CREATE_NEW_PROCESS_GROUP | CREATE_UNICODE_ENVIRONMENT | (Kernel32Util.getOSVersion() >= 0x602 ? 0 : CREATE_BREAKAWAY_FROM_JOB) | CREATE_NO_WINDOW;
            Kernel32Util.assertTrue(Advapi32.INSTANCE.CreateProcessAsUserW(hToken.getValue(), // executable name
            WString.toNative(lpApplicationName), // command line
            WString.toNative(lpCommandLine), // process security attribute
            null, // thread security attribute
            null, // inherits system handles
            true, // selected based on exe type
            dwCreationFlags, EMPTY_ENV, WString.toNative(Objects.toString(lpCurrentDirectory, null)), startupInfo, lpProcessInformation));
        });
    } catch (Win32Exception ex) {
        throw new NotExecutableException(ex);
    }
    return lpProcessInformation;
}
Also used : PROCESS_INFORMATION(jnc.platform.win32.PROCESS_INFORMATION) NotExecutableException(cn.edu.zjnu.acm.judge.core.NotExecutableException) STARTUPINFO(jnc.platform.win32.STARTUPINFO) WString(jnc.platform.win32.WString) Win32Exception(jnc.platform.win32.Win32Exception)

Aggregations

NotExecutableException (cn.edu.zjnu.acm.judge.core.NotExecutableException)1 PROCESS_INFORMATION (jnc.platform.win32.PROCESS_INFORMATION)1 STARTUPINFO (jnc.platform.win32.STARTUPINFO)1 WString (jnc.platform.win32.WString)1 Win32Exception (jnc.platform.win32.Win32Exception)1