private void RunExportCommand()
{
try
{
appLogger.WriteLog("RunExportCommand Method.");
appLogger.WriteLog("Starting exporting data to dump file.");
using (Process processExp = new Process())
{
string fileName = "exp.exe";
processExp.StartInfo.FileName = fileName;
processExp.StartInfo.Arguments = GetCommandString();
processExp.StartInfo.CreateNoWindow = true;
processExp.StartInfo.UseShellExecute = false;
processExp.StartInfo.RedirectStandardError = true;
processExp.StartInfo.RedirectStandardOutput = false;
processExp.StartInfo.RedirectStandardInput = true;
appLogger.WriteLog("Before Start");
processExp.Start();
appLogger.WriteLog("After Start");
appLogger.WriteLog("Started exporting data to dump file.");
processExp.StandardInput.AutoFlush = true;
processExp.StandardInput.Close();
appLogger.WriteLog("Before WaitForExit");
processExp.WaitForExit(Int32.MaxValue);
appLogger.WriteLog("After WaitForExit");
}
appLogger.WriteLog("Successfully exported data to dump file.");
}
catch (Exception e)
{
appLogger.WriteLog("Exception while exporting data. " + e.ToString());
throw new Exception("Exception while exporting data.", e);
}
}
在此代码processExp.WaitForExit(Int32.MaxValue)
行中没有执行,但在该文件行工作之前。如果我使用创建的filename.txt(log)
来复制或移动,则会显示舔错误
" IsErrorOccurred System.IO.IOException发生错误:进程无法访问文件' C:MyBKP \ BAK_01_01062017.txt'因为它正被另一个进程使用。"