knowing when a Process finsihed the Start

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

Hi,

I want my application to Start another application. I do it like this:
Dim prcSiclid As New Process
prcSiclid.StartInfo.UseShellExecute = True
prcSiclid.StartInfo.RedirectStandardOutput = False
prcSiclid.StartInfo.WorkingDirectory = strDeskTop
prcSiclid.StartInfo.FileName = strDeskTop & "\TBEN.lnk"
prcSiclid.Start()

After starting the new application (TBEN) I have to start a scritp that does
the login in that application. The problem is: starting tha application
takes some time (2-3 seconds), so I need to wait untill the application has
fully started. So what I basically need is soem kind of event that tells me
that the application finished the Start, or a way to see this (I can
eventually work with a timer to see if it has alreaddy finished).

Does anybody knows how to do this? Any help would really be appreciated!

Thanks a lot in advance,

Pieter
 
Hi Pieter,

Does that application throw something on the commandline, maybe you can than
use the redirectStandardOutput.

(Is very simple to get)

Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop

And then in that loop something as
if sb.tostring = "blabla"
exit do
end if

Cor
 
* "Cor Ligthert said:
Does that application throw something on the commandline, maybe you can than
use the redirectStandardOutput.

Maybe it throws "Starting, please wait..." onto the standard output :-).
 
It doesn't work :-(
If I want to use that I need to set prcSiclid.StartInfo.UseShellExecute =
False and prcSiclid.StartInfo.RedirectStandardOutput = True. But than my
application throws an exception when it wants to start the process:

"An unhandled exception of type 'System.ComponentModel.Win32Exception'
occurred in system.dll
Additional information: %1 is not a valid Win32 application"

The code I use is this:
prcSiclid = New Process
prcSiclid.StartInfo.UseShellExecute = False
prcSiclid.StartInfo.RedirectStandardOutput = True
prcSiclid.StartInfo.WorkingDirectory = strDeskTop
strDeskTop = "C:\Documents and Settings\COUCKE\My
Documents\Attachmate\Sessions"
prcSiclid.StartInfo.FileName = strDeskTop & "\TBEN.edp"
'prcSiclid.EnableRaisingEvents = True
prcSiclid.Start()

Dim sr As IO.StreamReader = prcSiclid.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
MsgBox(sb.ToString)

Anybody knows a solution?
 
Hi Pieter,

Or I oversee something, but I thought I have a piece of running program
what I can almost lay upon it. I gues the strDesktop is wrong

Cor
 
If I use this, it works fine, but I don't know when it is finished than...
prcSiclid = New Process

prcSiclid.StartInfo.UseShellExecute = True

prcSiclid.StartInfo.RedirectStandardOutput = False

prcSiclid.StartInfo.WorkingDirectory = strDeskTop

strDeskTop = "C:\Documents and Settings\COUCKE\My
Documents\Attachmate\Sessions"

prcSiclid.StartInfo.FileName = strDeskTop & "\TBEN.edp"

'prcSiclid.EnableRaisingEvents = True

prcSiclid.Start()
 
Hi DraguVaso,
If the application has an UI you can use Process.WaitForInputIdle. When this
method returns the process is started.
 
Hi Pieter,

I do not know if the solution from Stoitcho fits, that is absolute better I
think.

However my idea was to catch the first text on the commandline and than to
exit.

So it is looping reading and then something in the loop however it can even
be this.

Do Until input = asc("P") ' And that P is the first character that will be
displayed on console
exit do
Loop

Cor
 
Back
Top