关于使用CreateProcess,执行一个CMD指令遇到的问题,很着急,请大家帮忙啊,谢谢!
关于使用CreateProcess,执行一个CMD指令遇到的问题,很着急,请大家帮忙啊,谢谢!
char strCommandLine[200] = "cmd /c C:\\Progra~1\\mytest\\mytest.exe";
if( !CreateProcess( NULL, // No module name (use command line).
strCommandLine,
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
CREATE_NO_WINDOW, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi // Pointer to PROCESS_INFORMATION structure.
)
)
{
bReturnVal = FALSE;
}
else
{
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
如果把strCommandLine中的C:\\Progra~1换成C:\\Program Files,其他的不变,就提示出错,也就是说,只要有空格,就会报错,请问怎么处理这个问题,因为可能路径不会是固定的,万一有空格就会失败了,请大家帮忙啊,谢谢!