CommandLine commandLine = CommandLine.parse("\"" + mysqlDir + "mysqldump\"");
commandLine.addArgument("--host=192.168.42.161");
commandLine.addArgument("--port=" + port);
commandLine.addArgument("--user=" + username);
commandLine.addArgument("--password=" + password);
commandLine.addArguments("--databases " + database);
commandLine.addArgument("--result-file=" + directory + "/" + filename);
commandLine.addArgument("--default-character-set=utf8");
//线程看护狗,kill run-away thread
ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
//执行者
Executor executor = new DefaultExecutor();
//正常执行后的退出码
//executor.setExitValue(1);
//安装看护狗
//executor.setWatchdog(watchdog);
//执行命令,收集结果(供程序使用)
int exitvalue = executor.execute(commandLine);
if (executor.isFailure(exitvalue))
{
flag = false;
}
else
{
flag = true;
//子进程执行成功相应操作
}
分享到:
2011-09-15 17:37
浏览 580
分类:数据库
评论