E
E
Edward2015-06-04 02:09:52
C++ / C#
Edward, 2015-06-04 02:09:52

Pass child process CTRL-C in C/C++?

STARTUPINFO cif;
  ZeroMemory(&cif,sizeof(STARTUPINFO));
  PROCESS_INFORMATION pi;
  //AllocConsole();
  CreateProcess("c:\\windows\\system32\\defrag.exe","foo D:",
  NULL,NULL,TRUE,(CREATE_NEW_PROCESS_GROUP,CREATE_NEW_CONSOLE),NULL,NULL,&cif,&pi);
  GenerateConsoleCtrlEvent (CTRL_C_EVENT, pi.dwProcessId);

Does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2015-06-04
@Nipheris

a,b in C/C++ is calculated as b. You took two constants separated by commas into parentheses, after which they began to be perceived as a "comma" operation, the result of which is the second argument. Those. if you write a = (67, 23), then the value 23 will get into the variable a. In your case, only the CREATE_NEW_CONSOLE flag will be passed to the function, and, judging by MSDN, you need both to create a new process group. Connect the flags as it was originally necessary - through the logical or operation, i.e. "|" - and everything should work. Instead of what's in parentheses, it would be:
CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE
Edit: No, CTRL-C doesn't seem to be supported for process groups, try CTRL-BREAK. And these flags are mutually exclusive, judging by the docks. CREATE_NEW_PROCESS_GROUP: This flag is ignored if specified with CREATE_NEW_CONSOLE.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question