problem excuting process in different directory

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2009
Posts: 11
Reputation: tig2810 is an unknown quantity at this point 
Solved Threads: 0
tig2810 tig2810 is offline Offline
Newbie Poster

problem excuting process in different directory

 
0
  #1
Aug 12th, 2009
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.

  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. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 58
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

Re: problem excuting process in different directory

 
0
  #2
Aug 12th, 2009
What exception it is throwing?
How do you know its not working?
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 11
Reputation: tig2810 is an unknown quantity at this point 
Solved Threads: 0
tig2810 tig2810 is offline Offline
Newbie Poster

Re: problem excuting process in different directory

 
0
  #3
Aug 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,251
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 578
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: problem excuting process in different directory

 
0
  #4
Aug 12th, 2009
To catch very low level exceptions you need to capture stdout and stderr:
  1. AppName.exe > debug.txt 2>&1

Review debug.txt after the execution fails
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 11
Reputation: tig2810 is an unknown quantity at this point 
Solved Threads: 0
tig2810 tig2810 is offline Offline
Newbie Poster

Re: problem excuting process in different directory

 
0
  #5
Aug 12th, 2009
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!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC