I have a C ++ MFC program that works, but I would also like to be able to call a simpler version via the command line. (This works using the version of the cmd line if there are arguments to the cmd line.) I would like the program to use the current "cmd" window that is open to run, and create a new shell for it. In InitInstance (), I have ...
CString cmdLine; cmdLine.Format("%s", this->m_lpCmdLine); if(cmdLine.IsEmpty()) dlg.DoModal(); // Run application normally else { CString header = "Welcome to the program!"; AttachConsole(ATTACH_PARENT_PROCESS); // Use current console window LPDWORD charsWritten = 0; WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), header, header.GetLength(), NULL, NULL); }
How do I access my program? cin doesn't seem to work. I tried something like this:
char input[10] = ""; while((strcmp(input, "q") != 0) && (strcmp(input, "quit") != 0)) scanf("%s", input);
But it does not work because the command window is waiting for a new prompt.
source share