I am trying to create a shell that allows a user to input "ping" commands and use CreateProcess() to execute the command based on user input. I am running into trouble getting the ping command to work when dealing with variables. For example the code below works just fine as long as I have the L in front of the string. However, the string has to be given by user input so after some research I ran across a possible substitution of the L cast in the form of a wchar_t variable.
if (strcmp(buffer, "ping") == 0 || strcmp(buffer, "ping &") == 0){
LPCTSTR path = L"C:\\Windows\\System32\\PING.exe";
LPTSTR link = L"-t www.yahoo.com";
CreateProcess(path,
link,
NULL,
NULL,
0,
0,
NULL,
NULL,
&start,
&info);
if (strcmp(buffer, "ping") == 0){
WaitForSingleObject(info.hProcess, INFINITE);
}
CloseHandle(info.hProcess);
CloseHandle(info.hThread);
printf("MyShell: ");
scanf("%s", buffer);
If I do this change, it stops working (console crashes, no output).
wchar_t wideC = "-t www.yahoo.com";
LPCTSTR path = L"C:\\Windows\\System32\\PING.exe";
LPTSTR link = wideC;
I've tried casting different types of variables both in the CreateProcess() arguments and outside. I don't know what else to do. How can I get the user scanf() into a variable that will work as an argument for creating a process?