Calling a Dos app, and waiting...

samsmithnz

Senior Contributor
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
I'm trying to run a BCP command from my VB.NET app. Currently it looks like this:

Code:
                objCmdLine = New System.Diagnostics.ProcessStartInfo("bcp.exe")
                objCmdLine.Arguments = strBCPString
                Process.Start(objCmdLine)

After I run this, I connect to a SQL Server and run a stored procedure that processes the data that was imported in. My problem is that this method doesn't wait for the bcp command to finish, and hence the stored procedure I call afterwards ALWAYS fails.

What can I do to wait for the BCP command to finish?
 
I thought I'd found it. Rearranging the end there should work...
Code:
dim objProcess as New System.Diagnostics.Process
objProcess.Start(objCmdLine)
objProcess.WaitForExit()

but it doesn't.... It returns the error "No process was associated with this object"...
 
Shell

Have you tried using the shell command to run the .exe? I've used this in the past and you can pass it true/false if you want it to wait until the execution is complete before continuing.

Visual Basic:
Shell(".\bcp.exe", AppWinStyle.Hide, True)

Additionally as a cheap method of a progress bar... you can .show a form right before this that has information that the event is running... then .close the form after the Shell command is complete. The only note though is that if you .show a form before the command, toss in a .refresh as well to make sure it draws correctly.

-Falcon
 
Back
Top