View Single Post
Old 04-06-2007   #9 (permalink)
Peter Duniho


 
 

Re: Wrap command shell in System.Diagnostics.Process

On Fri, 06 Apr 2007 10:11:42 -0700, Jon Davis
<jon@REMOVE.ME.PLEASE.jondavis.net> wrote:

> Lots of people have PowerShell, it's a Windows Update piece.
>
> Just swap out PowerShell for CMD.exe:


I don't know what you mean by "Windows Update piece". I have Windows
Update, use it all the time, but don't have PowerShell installed.

In any case, thank you for the sample code. On my computer, it runs just
fine as long as I remove the extra ReadLine you've got (the one commented
"command entry (echo)").

For what it's worth, all I did was break in the debugger when the program
got blocked, and saw that it was waiting at that line which showed that
you never got to the point of writing to the input stream, meaning you
were reading too many "discardable" lines up front.

Of course, one of the things this exercise illustrates is the fragility of
the approach you're using. Even if it works fine now (as it does on my
computer...can't say whether that's true on yours), you're tied to a
precise sequence of lines of input and output. A trivial bug in your own
code causes the whole thing to just stop, and of course if there are any
changes to the external console application that can really mess things up
too (either by making your application just stop in the wrong place, or
perhaps worse by causing your application to send the wrong commands to
the process).

Granted, this is all just sample code so who knows whether this is really
how you're doing things. But if it is, beware. Many pitfalls lie ahead.

Pete
My System SpecsSystem Spec