对现有数据库 database1进行备份,但是不知道为什么备份得到的文件就只有0 kb ,求 高手帮忙解答,谢谢,废话不说,上代码CString path = "/c c:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\mysqldump -uroot -p123456 database1 >D:/beifeng733.sql";
CString program = "cmd.exe";
HINSTANCE hinstSetup = ShellExecute(this->m_hWnd,"open",program,path,NULL,0);
在线等,分不够 加~~~
CString program = "cmd.exe";
HINSTANCE hinstSetup = ShellExecute(this->m_hWnd,"open",program,path,NULL,0);
在线等,分不够 加~~~
===bin后面怎么只有一个\?改成两个\\
改成 CString path = " /c......
在/C前加空格。
另外,你这是什么数据库啊?
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
CString program = " cmd.exe ";
HINSTANCE hinstSetup = ShellExecute(this->m_hWnd,"open",program,path,NULL,0);
这样试试吧。既然在cmd中直接执行可以。那么应该只是串的格式问题了。直接在cmd中输入命令和在CString中写串还是有一些地方需要注意的。
============
另外一个可能是Program Files的问题,你可以看一下以下文章
http://hi.baidu.com/vmwares/blog/item/a5cb810ac485f71e94ca6ba9.html
进行修改:
CString path = " \"/c c:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump -uroot -p123456 database1 >D:\\beifeng733.sql\"";
&pi这是什么意思?
\k的意思见下图:&si,
&pi 的意思见下面代码:
#include <windows.h>
#include <stdio.h>void main( VOID )
{
STARTUPINFO si;
PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) ); // Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
TEXT("MyChildProcess"), // 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 );
}
to :clever101我按你文章的方法做,但是就是不行,郁闷,能不能把你写的那部分代码贴上来看下啊
我告诉你,肯定可以的,我以前都测试通过了的。简要代码如下(详细代码在公司机子里,基于职业道德不能给你): STARTUPINFO si;
PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );CString strCmdLine;
// 这里mysqldump后面的参数你根据你的实际情况来设置,你可以现在控制台上测试,看能不能备份成功
strCmdLine.Format("cmd.exe \k \"mysqldump --host=168.168.168.59 --user=root --password=828707 student>E:\114.dmp\"");
::CreatProcess(NULL,
(LPSTR)(LPCTSTR)strCmdLine,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi
);
我使用的是MySQL Administrator V1.1, MySQL Query Browser V1.1, MySQL Server V5.0,操作系统是Windows XP sp2.祝你好运!
我把 \k \ 改为 \c \也是一样的