Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute: Executing a batch file and passing parameters + Waiting

Status
Not open for further replies.

rennis

Programmer
Dec 6, 2006
80
CA
Currently, I am using shellexecute to execute a batch file. The batch file gets passed parameters, and executes mysql.exe, which allows me to execute script files on a database.

For example:
result = ShellExecute(hwnd, "open", "theBatch.bat", parameter1 & " " & parameter2 & " " & parameter3 & " " & parameter4 & " " & parameter5 & " " & thePathToBatch, App.Path, 0)

Each parameter 1 through 5 is a required parameter for the mysql.exe (username, password, host, theDatabase, & the filename to execute,thepath to theBatch.bat, thepath to mysql.exe etc). Without these parameters, the mysql.exe wont execute correctly as it cant access the server.

BatchFile call to mysql ex:
%ThePathToMySql.Exe%mysql -h %parameter1% -u %parameter2% -p%parameter3% -B %parameter4% < %parameter5%

Problem:
The call to the ShellExecute command is in a for loop, because there is more then one file to execute. However, the second call to the ShellExecute happens before the first one gets to successfully completed.

Currently, i use sleep x after the first call to give it time to execute before continuing in the for loop, and this appears to work.

Question:
Is there something better then using sleep to be certain that the script has executed correctly, just incase the interval isnt enough time to execute the script?

I've tried placing '/wait' in the batch file before/after the call to the mysql.exe is made, but this doesn't seem to work. I've also looked at the ExecuteAndWait function, but Im wondering if this will allow me to pass the parameters 1 through 5 as listed above?

Any thoughts?
 
Do a search in this forum using the keyword: WaitForSingleObject
There are some examples.
There are also a couple of examples in this forum's FAQ section.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top