.net 코드에서 실행중인 공유 위치에 배치 파일이 있지만 배치 파일이 실제로 실행되지 않습니다. 배치 파일의 전체 코드가 작동하지 않습니다. 단지 부분 코드 만 작동합니다. 나는 .net 코드 실행이 완료되고 배치 파일의 실행을 중단한다고 가정합니다. 다음은 내 .NET 코드배치 파일이 C# 코드에서 실행되지 않음
private static void ExecuteCommand(string command, string arguments)
{
try
{
Console.WriteLine("Code execution starts");
Console.WriteLine("command: " + command);
Console.WriteLine("arguments: " + arguments);
var process = new Process();
process.StartInfo.FileName = command;
if (!string.IsNullOrEmpty(arguments))
{
process.StartInfo.Arguments = arguments;
}
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//process.StartInfo.CreateNoWindow = false;
//process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.UseShellExecute = true;
process.EnableRaisingEvents = true;
//process.StartInfo.RedirectStandardError = true;
//process.StartInfo.RedirectStandardOutput = true;
string stdError;
// process.Start();
Thread.Sleep(60000);
ThreadPool.QueueUserWorkItem(delegate
{
process.Start();
// process.WaitForExit();
});
//Thread.Sleep(60000);
//ThreadStart ths = new ThreadStart(delegate()
//{
// process.Start();
// //process.BeginOutputReadLine();
// //stdError = process.StandardError.ReadToEnd();
//});
//process.Start();
//process.BeginOutputReadLine();
//stdError = process.StandardError.ReadToEnd();
Console.WriteLine("Code execution ends");
}
catch (Exception e)
{
Console.WriteLine("Code execution error: "+e.Message +"||"+e.InnerException.ToString());
}
}
요구 사항이 배치 파일의 실행을 시작하고 NTO 배치 파일 실행의 출력 또는 마무리를 기다릴 않습니다이다. 내가 명령 프롬프트 또는 Windows 탐색기에서 배치 파일을 실행하면 정상적으로 작동합니다. 배치 파일이 없거나 권한 문제가있을 때 예외를 처리해야하기 때문에 .net 코드에서 cmd.exe를 사용할 수 없습니다.
'process.StartInfo'에서'WorkingDirectory' 설정을 시도 했습니까? 배치가 중단 된 배치 파일의 실행을 확인합니다. 어쩌면 어떤 오류가있을 수 있습니다. – JeffRSon