c++ - Dos window show up then disappears immidiately -


when run codes below, dos window show immidiately disappear. want window stay , wait user's next command input. should startupinfo.hstdinput if want keep window showing , have use createprocess in project not winexec etc.

int winapi winmain(                    hinstance hinstance,                    hinstance hprevinstance,                    lpstr lpcomline,                    int ncmdshow) {     security_attributes secattr;      handle hread,hwrite;  secattr.nlength = sizeof(security_attributes);  secattr.lpsecuritydescriptor = null;  secattr.binherithandle = true;  if (!createpipe(&hread,&hwrite,&secattr,0))  {      return false;  }   char command[1024]; strcpy(command,"ping 192.168.0.1");  startupinfo startupinfo; process_information processinfo;  startupinfo.cb = sizeof(startupinfo);  getstartupinfo(&startupinfo);  startupinfo.hstderror = hwrite;      startupinfo.hstdoutput = hwrite; startupinfo.hstdinput = hread;           startupinfo.lptitle = "cmd";  if (!createprocess(null, command,null,null,true,null,null,null,&startupinfo,&processinfo))  {          messagebox(null, "failed", null, mb_ok);         closehandle(hwrite);          closehandle(hread);          return false;  }   closehandle(hwrite);  closehandle(hread);  return 0; } 

if problem process window closes immediately, may should add pause ... able see results of ping command..

now, in no way c++ expert ... suggest, try along following lines of code...

createprocess(                         "c:\\windows\\system32\\cmd.exe",                         "/k ping 192.168.0.1 && pause && exit",                         null,                         null,                         false,                         0,                         null,                         null,                         &startupinfo,&processinfo);   

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -