Your process may be blocking on the redirected standard output. Take a
look a the examples on this page:
<
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfsystemdiagnosticsprocessstartinfoclassredirectstandardoutputtopic.asp>
Katy
From: "=?Utf-8?B?TGFyc0o=?=" <
[email protected]>
|
| Hi!
| Working with an VB.NET app that calls a lot of 3:rd party console
programs
| via the
| Process class. All calls are made with this pattern:
|
| Dim p as New Process()
| p.StartInfo.FileName = <full path to the exe-file>
| p.StartInfo.Arguments = <arguments to the app>
| p.StartInfo.CreateNoWindow = True
| p.StartInfo.UseShellExecute = False
| p.StartInfo.RedirectStandardError = True
| p.StartInfo.RedirectStandardOutput = True
| p.start()
| p.WaitForExit()
| Dim sr As StreamReader = p.StandardOutput
| Dim stdOut As String = sr.ReadToEnd()
| sr.Close()
| p.Close()
|
| This works fine for all exe-files EXCEPT ONE! Strange... Then I tried to
| figure out why it doesn't work. But this really confuses me..
|
| I changed to using the shell instead:
|
| Dim p as New Process()
| p.StartInfo.FileName = <full path to the exe-file>
| p.StartInfo.Arguments = <arguments to the app>
| p.StartInfo.UseShellExecute = True
| p.start()
| p.WaitForExit()
| p.Close()
|
| This works (as well as when i run exactly the same command in a console).
| But I don't want the console window to pop up so therefore I add the
| following line:
|
| p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
|
| Now it doesn't work again!!! This is really true, it only works when the
| console window is visible!!!
| It must have something to do with the program I'm calling but also isn't
| this strange by Process?
| The program I call produces about 50 lines of output, takes about 15
seconds
| to execute and creates a new file (which name is given as an argument).
It
| really takes 15 seconds in both cases when it works or not.
| But the output (= the file) is only created when the console is visible.
|
| I would be very glad if anyone has any clue to this.
|
| --
| Regards,
| Lars Jönson
|
|