c++的mysql备份
我用mysqldump备份数据库,用CreateProcess方式时程序就停在命令行界面不动了,用ShellExecute执行也没有结果。
直接在cmd下运行mysqldump是可以的,我的环境是64位win7 vs2008。
CString strCmdLine = "";
strCmdLine.Format("cmd.exe \c \"mysqldump --host=localhost --user=root --password=root
--port=333 dbname >aaaa.sql\"");
STARTUPINFO si; //一些必备参数设置
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
PROCESS_INFORMATION pi; //必备参数设置结束
if( !CreateProcess( NULL, // No module name (use command line)
(LPSTR)(LPCTSTR)strCmdLine, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // 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
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );