943,719 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 603
  • C# RSS
Aug 12th, 2009
0

problem excuting process in different directory

Expand Post »
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.

C# Syntax (Toggle Plain Text)
  1. private void RunMacro(string MacroName)
  2. {
  3. //System.Diagnostics.Debugger.Break();
  4.  
  5. Process sdProc = new Process();
  6. string strCmdLine = @"D:\" + MacroName + ".bat";
  7.  
  8. sdProc.StartInfo = new ProcessStartInfo("CMD.exe");
  9. sdProc.StartInfo.Arguments = strCmdLine;
  10. sdProc.Start();
  11. sdProc.WaitForExit(132000);
  12. sdProc.Close();
  13. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tig2810 is offline Offline
20 posts
since Jul 2009
Aug 12th, 2009
0

Re: problem excuting process in different directory

What exception it is throwing?
How do you know its not working?
Reputation Points: 165
Solved Threads: 59
Posting Pro in Training
DangerDev is offline Offline
485 posts
since Jan 2008
Aug 12th, 2009
0

Re: problem excuting process in different directory

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tig2810 is offline Offline
20 posts
since Jul 2009
Aug 12th, 2009
0

Re: problem excuting process in different directory

To catch very low level exceptions you need to capture stdout and stderr:
dos Syntax (Toggle Plain Text)
  1. AppName.exe > debug.txt 2>&1

Review debug.txt after the execution fails
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Aug 12th, 2009
0

Re: problem excuting process in different directory

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
"cd\\"
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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tig2810 is offline Offline
20 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: assigning null values
Next Thread in C# Forum Timeline: recommend good online courses for SQL, data controls?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC