i'm trying to execute a .bat file through a c# console application using code from here: Service hangs up at WaitForExit after calling batch file
Kevin's solution kinda works, but some commands in my .bat file get ignored for some reason, but when i manually execute the .bat file all commands work just fine.
e.g. xcopy command doesn't work while executing .bat from console app, but start command works fine.
Any idea why this happens?
p.s. recently i found that if the program is being launched from command prompt, it works well. How come? Still i need to put it on autorun, so this doesn't solve the problem.
Also, if launched by clicking on exe file, output shows
xcopy folder1 folder2
but if launched from command prompt, output shows
xcopy folder1 folder2
smth/smth.smth copied
....
5 files copied.
And it actually is being copied.
proc.StartInfo.FileName = target;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit
(
(timeout <= 0)
? int.MaxValue : timeout * NO_MILLISECONDS_IN_A_SECOND *
NO_SECONDS_IN_A_MINUTE
);
errorMessage = proc.StandardError.ReadToEnd();
proc.WaitForExit();
outputMessage = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();