First, fgets
will get a string with charactor ‘\n’ when size of inserted string <(255-1). So, let’s set the \n
to \0
:
fgets(cmd, 255, stdin);
cmd[strlen(cmd) - 1] = '\0';
CreateProcess(cmd, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
Second,
more instances of cmd to popup in the command line.
If what you mean is like:
This is because the input focus of the cmd process and the current process alternately appears in the same console, not always creating a new instance.
If you CreateProcess
with CREATE_NEW_CONSOLE
:
CreateProcess(cmd, NULL, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
solved CreateProcess causing problems