RE: Strange behavour of Process



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=?=" <LarsJ@xxxxxxxxxxxxx>
|
| 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
|
|

.



Relevant Pages

  • Re: Printing from an ASP.NET page
    ... webservice or even simple network socket programming is ok(or if you ... For the console application, do not call it from your ASP.NET application, ... you are doing the samething as you try calling winform printing ... The following code fails at "Dim p As System.Diagnostics.Process." ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Console Application Alternate Windows Credentials
    ... ConsoleApplicationCredentials to the module of my console application ... phtoken As IntPtr) As Boolean ... Dim lpMsgBuf As String ... Dim impersonatedUser As WindowsImpersonationContext ...
    (microsoft.public.dotnet.security)
  • Re: vb6 run from and output to command window
    ... VB doesn't really create true console applications (because the linker ... allocate the console window, and read/write from/to it. ... Private Declare Function AllocConsole Lib "kernel32" As Long ... Dim lResult As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: vb6 run from and output to command window
    ... > VB doesn't really create true console applications (because the linker ... AllocConsole to allocate the console window, ... > Dim lResult As Long ... > Function ConsoleWriteLn(sOutput As String) As Boolean ...
    (microsoft.public.vb.general.discussion)
  • RE: Strange behavour of Process
    ... Dim p as New Process ... 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 ... this strange by Process? ...
    (microsoft.public.dotnet.framework)