Hi all

I'm literally begging for help here. I have a program that as part of other things, executes a batch file. In visual studio 2008,it works fine either either as debug or release. If I execute it fro the debug/release directories it works fine. if I copy the debug/release directory somewhere else, sdProc.Start() will not execute.

I'm copying it on the same drive. If I move the whole VS project directory it works. I just cant move the debug dir on it's own.

Any help appreciated. I'm just not able to debug the problem.

private void RunMacro(string MacroName)

            Process sdProc = new Process();
            string strCmdLine = @"D:\" + MacroName + ".bat";

            sdProc.StartInfo = new ProcessStartInfo("CMD.exe");
            sdProc.StartInfo.Arguments = strCmdLine;

What exception it is throwing?
How do you know its not working?

The bat file is never executed as the program in the .bat file would write to a log and show up on screen. everything else is fine. I cant catch any errors, even the lowest 'Exception' but I think there might be an 'InvalidOperationException', even though I cant catch it. I see this when I hover over the proc object while debugging.

To catch very low level exceptions you need to capture stdout and stderr:

AppName.exe > debug.txt 2>&1

Review debug.txt after the execution fails

I am so mad at myself for not thinking of that!! The batch file was calling my .net exe which wrote new batch files. I added stderr to that and found the error straight away!
I added a streamwriter line to add
to the beginning of the batch file and now it works!

(I know you are all wondering why the cmd.exe and batch files... the exe is also calling an old cobol app and it just wont execute properly any other way. it flatly dies if executed from powershell)

Sknake - you are the master! Thanks very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.