Anthony Maimone

This question may seem a little odd but I am attempting to run VS2005 through a process and execute a specific command and I waitforexit(). I am redirecting my input and output successfully but every now and then I happen to receive a Window Error Reporting Window/Message. The problem is that I am remoting, so when this message/window occurs during the process execution, I will hang unless I log into the other (remoting) machine and close the window.

Is there any way to programatically kill this window or possibly disable the message/window from occurring I have thought of running VS in a silent execution ( I have yet to find a way to do so). I have also attempted to see if there is anything being lauched when this occurs compare to when it does not.

Any ideas

Thank you,

Tony



Re: Visual C# General Process.waitforexit() not exiting

Peter Ritchie

Could you be specific with the error you are receiving

This only occurs when you are redirecting input and output






Re: Visual C# General Process.waitforexit() not exiting

Anthony Maimone

No, I can redirect input and output without a problem. The error that I am receiving is the general windows error reporting and unfortunately, it is in Japanese so I do not know what the exact error is, but it is the general error.

I do not have the code in front of me but I set up delegates/threads to read redirected the error and output after I exit the entire process.

I can't come up with anything and I am able to run the same process on my own computer but I am not able to do this one particular command through remoting. I wil try it tomorrow remoting on a non-Japanese machine at work and I will post my findings regardless.

thanks
tony




Re: Visual C# General Process.waitforexit() not exiting

Manju Sandhu

Hi,

Are you running console "cmd"

If yes then you have to type exit also.

Regards,

Manju Sandhu





Re: Visual C# General Process.waitforexit() not exiting

J Andrews

If you an idea of how much time your process is going to take, then you can use

bool exitted = process.WaitForExit(timeInMilliSeconds);

if(exitted)
{
// Process exitted before timeout period.
}
else
{
// Print error message
}

This may not be related to what you are doing, but I had an experience where the process would not exit if I redirected its output. Try disabling the output redirection and see if the process exits. Give it a try, it might work.





Re: Visual C# General Process.waitforexit() not exiting

Anthony Maimone

I would like to try that, but it is too much of a hack. I have too many different commands that take different amounts of time (30 seconds to 25 minutes) so there is no real time setting that I could place without destroying my performance. This function has been working correctly for multiple commands over the last 6 months and now it decides to *** out on me. I tried it on a different computer without any problems (which is really messing with me). I know that it is NOT the output/error redirection because a new WINDOW is being created on the server that I am remoting to. As soon as I close that window, my process exits as expected and the correct output is displayed on the User side.

Thank you for your help, but I am getting really frustrated with this problem.





Re: Visual C# General Process.waitforexit() not exiting

Peter Ritchie

Without knowing the detail of the message we're just guessing at the problem...

Have you installed .NET 3.5 beta or Visual Studio 2008 beta at all

How are you using Process to start the program, Process.Start("file.exe"), or are you using ProcessStartInfo






Re: Visual C# General Process.waitforexit() not exiting

Anthony Maimone

No, I have .NET 2003 and .NET 2005 installed.

Code Block

proc = new Process( );

proc.EnableRaisingEvents = false;

procSI = new ProcessStartInfo( );

procSI.UseShellExecute = false;

procSI.RedirectStandardInput = true;

procSI.RedirectStandardOutput = true;

procSI.RedirectStandardError = true;

procSI.FileName = "cmd.exe";

procSI.WindowStyle = ProcessWindowStyle.Hidden;

procSI.CreateNoWindow = false;

proc.StartInfo = procSI;

I then set up a new thread for both the StandardError and StandardOutput

Code Block

proc.Start( );

sIn = proc.StandardInput;

sIn.AutoFlush = true;

I then write my commands and

Code Block

sIn.Close();

if( redirecting standard out )

{

Start thread for st. out

}

If( redirecting standard error )

{

Start thread for st. error

}

Proc.WaitForExit(); <-------- this is where the Generic Windows Error Reporting window occurs.

I translated what I could from the Window that pops up...

} Microsoft Visual Studio 2005 K

into

Because problem occurs, it ends Microsoft Visual Studio 2005. We applying inconvenience, there is no excuse.

Thanks again for all of your time.

Tony





Re: Visual C# General Process.waitforexit() not exiting

eradicator

sIn.Close();

Why are you doing this You don't own this stream so you shouldn't be closing it.

Proc.WaitForExit();

Is this a typo Before you were talking about a variable named "proc", not "Proc". So is this simply a null reference because you're trying to invoke a method on a different reference than "proc"




Re: Visual C# General Process.waitforexit() not exiting

Peter Ritchie

You don't want to close the sIn object until after the application has exited if you're redirecting. If the application writes to standard output or reads from standard input after you've closed either one of those it could cause an exception.

Do you have the stack trace from that error message






Re: Visual C# General Process.waitforexit() not exiting

eradicator

Peter Ritchie wrote:

You don't want to close the sIn object until after the application has exited if you're redirecting.

One shouldn't close any of those streams at all. The Process object owns them and it is the one responsible for cleaning up after itself. One should at best call Process.Dispose() after finished with the Process object.




Re: Visual C# General Process.waitforexit() not exiting

Anthony Maimone

I created the StreamWriter sIn prior to creating the proc Process object. I then redirect the input after the proc.Start() command, so how do I not own this Regardless, I can make the change to move the sIn.Close() to after the WaitForExit call to see if this makes any changes.

The Proc was a type, it should have been proc.

Again, it is not an error message, so there is no stack trace. My StandardError redirection is empty and the Standard OUtput redirection contains what I expected, but nothing indicating an error occurred. this is why everything still works after I close the Windows Error Reporting window.

I will post what happens after I move the sIn.Close() line below the WaitForExit() line.

Thanks,

Tony





Re: Visual C# General Process.waitforexit() not exiting

Peter Ritchie

eradicator wrote:
Peter Ritchie wrote:

You don't want to close the sIn object until after the application has exited if you're redirecting.

One shouldn't close any of those streams at all. The Process object owns them and it is the one responsible for cleaning up after itself. One should at best call Process.Dispose() after finished with the Process object.
You certainly don't need to (I.e. it's redundant); but it shouldn't cause a problem after the process has exited. Process.Close is the recommended method of closing the standardinput and standardoutput (and standarderror) streams.




Re: Visual C# General Process.waitforexit() not exiting

Anthony Maimone

Ok, I am doing Process.Close in the finally block of my code, so it should be taken care of then.

Pardon my "not own"ing comment that I made previously. I just came back form lunch and was missing the fact that the process has control of this.





Re: Visual C# General Process.waitforexit() not exiting

eradicator

Process.Close is the recommended method of closing the standardinput and standardoutput (and standarderror) streams.

I would be surpised if the Dispose method didn't call Close, at least as part of its operation. I would favor using the fact that since Process implements IDisposable (indirectly thru extending Component which implements it), one should invoke Dispose and let that to the proper cleanup. I wouldn't recommend invoking Process.Close instead of, nor in addition to, Process.Dispose.