предпочтительнее: не теряет цикл ЦП, переасывающая stdio через трубы в руку,
non-conderation: универсальные приложения < /p>
Использование простого запуска Createprocess: < /p>
.
Код: Выделить всё
// Grab current console handles so we can forward them
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hStdErr = GetStdHandle(STD_ERROR_HANDLE);
// Setup process creation
STARTUPINFOA si = {};
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = hStdIn;
si.hStdOutput = hStdOut;
si.hStdError = hStdErr;
// Disable Ctrl-C, let the child handle it.
// Ensure our io activities are finished
_flushall();
// Create the child process in a new process group
BOOL success = CreateProcessA(
nullptr, // No module name (use command line)
const_cast(cmdline.c_str()), // Command line
nullptr, // Process handle not inheritable
nullptr, // Thread handle not inheritable
1, // Set handle inheritance to TRUE
0, // Creation flags - normal priority
nullptr, // Use parent's environment block
nullptr, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
gProcessInfo // Pointer to PROCESS_INFORMATION structure
);
if (!success) return -1;
// The child is responsible for ctrl-c as of now.
SetConsoleCtrlHandler(consoleCtrlHandler, TRUE);
Код: Выделить всё
> python
3.12.10
>>> os.isatty(0)
True
>>> #
против < /p>
> mywrapper python
3.12.10
>>> os.isatty(0)
True
>>> ^[[A #
С одной стороны, я отмечаю < /p>
> python -c 'import os; os.system("python")'
3.12.10
>>> os.isatty(0)
True
>>> ^[[A #
Подробнее здесь: [url]https://stackoverflow.com/questions/79696425/posix-exec-like-transfer-of-console-handles-to-createprocess-child[/url]