Sequential run of DOS program via SHELL command 
Author Message
 Sequential run of DOS program via SHELL command

I need to run a DOS EXE file and then call a Windows apllication next.  
According to what I make of VB use of the SHELL command would look like
the way to go on this.  Shell, however, doesn't necessarily wait for what
is running to complete before the next piece of code executes.  If I use
the following piece of code there is no guarentee that program1 completes
execution before program2 begins.

dim x,y
   x=SHELL("program1")
   y=SHELL("program2")

So, what I need to do is make sure program1 executes and is completed
before program2 activates.  Anyone have any ideas?



Fri, 28 Nov 1997 03:00:00 GMT  
 Sequential run of DOS program via SHELL command
You can do this a couple of different ways.
1)  At the very end of the first dos app, create a file.  After the first
shell() command in vb, put a while (FileNotFound()) loop before the next
shell() command.

2)  There are a couple of windows api calls that will let you get the number
of apps running (I think they're called something like GetModuleUsage and
GetTask...something or other).  So you can get the number of apps running,
then shell the first app, wait until the number of apps drops down one, and
then shell the second app.  There is a problem here.  If the user starts
another app in the middle of all this you could be looping forever.

Good luck.

-Kim



Sat, 29 Nov 1997 03:00:00 GMT  
 Sequential run of DOS program via SHELL command

Quote:

>I need to run a DOS EXE file and then call a Windows apllication next.  
<snip>
>So, what I need to do is make sure program1 executes and is completed
>before program2 activates.  Anyone have any ideas?

See KnowledgeBase article Q96844, How to Determine When a Shelled
Process has Terminated.
--

Systems Analyst         WWW:    http://www.phoenix.net/USERS/getj


Sat, 29 Nov 1997 03:00:00 GMT  
 Sequential run of DOS program via SHELL command

Quote:

>I need to run a DOS EXE file and then call a Windows apllication next.  
>According to what I make of VB use of the SHELL command would look like
>the way to go on this.  Shell, however, doesn't necessarily wait for what
>is running to complete before the next piece of code executes.  If I use
>the following piece of code there is no guarentee that program1 completes
>execution before program2 begins.
>dim x,y
>   x=SHELL("program1")
>   y=SHELL("program2")
>So, what I need to do is make sure program1 executes and is completed
>before program2 activates.  Anyone have any ideas?

Look in the Knowledge Base for the topic "How to tell when a Shelled
task has finished".  Basically, it boils down to placing a loop around
each SHELL stmt, and checking the shelled window status each pass thru.
You throw in a DoEvents in the loop, and voila the second SHELL is not
started until the first one finishes.

There is an example in the KB.  This particular article is also in the
VB Help file, if memory serves me correctly.



Sat, 29 Nov 1997 03:00:00 GMT  
 Sequential run of DOS program via SHELL command
: I need to run a DOS EXE file and then call a Windows apllication next.  
: According to what I make of VB use of the SHELL command would look like
: the way to go on this.  Shell, however, doesn't necessarily wait for what
: is running to complete before the next piece of code executes.  If I use
: the following piece of code there is no guarentee that program1 completes
: execution before program2 begins.

: dim x,y
:    x=SHELL("program1")
:    y=SHELL("program2")

: So, what I need to do is make sure program1 executes and is completed
: before program2 activates.  Anyone have any ideas?

Option Explicit

Declare Function GetModuleUsage% Lib "Kernel" (ByVal hModule%)

Sub Wait (x As Integer)
' Wait is called after you shell out and would like to wait for
' that external procedure or application to finish.
' x is the variable that was assigned the shell call.

       While GetModuleUsage(x) > 0    
          DoEvents                  
       Wend

End Sub

To call this use the something like the following:
Sub Form_Load()
Dim x As Integer

     x = shell("sample.exe")
     Call Wait(x)
     Debug.Print "Shelled program is done!"

End Sub

BTW I found the meat of this sub in a KB article which unfortunately I forgot
its title but it went something like "How to determine when a shelled
program is complete .

Good luck,
--
****************************************************************************
Ed Hernandez                                 North Broward Hospital District
Interface Programmer                         1608 Andrews Ave.


***************************************************************************



Mon, 01 Dec 1997 03:00:00 GMT  
 Sequential run of DOS program via SHELL command

Quote:

> I need to run a DOS EXE file and then call a Windows apllication next.
> According to what I make of VB use of the SHELL command would look like
> the way to go on this.  Shell, however, doesn't necessarily wait for what
> is running to complete before the next piece of code executes.  If I use
> the following piece of code there is no guarentee that program1 completes
> execution before program2 begins.
> dim x,y
>    x=SHELL("program1")
>    y=SHELL("program2")
> So, what I need to do is make sure program1 executes and is completed
> before program2 activates.  Anyone have any ideas?

Bill,

Email me if you would like to receive information regarding our XSpawn
product, which will allow you to spawn a program (Windows, DOS, OS/2,
Win32), wait for it to terminate and return its exit code
(ERRORLEVEL).

Yaniv Golan



Mon, 01 Dec 1997 03:00:00 GMT  
 Sequential run of DOS program via SHELL command

Quote:

>I need to run a DOS EXE file and then call a Windows apllication next.  
>According to what I make of VB use of the SHELL command would look like
>the way to go on this.  Shell, however, doesn't necessarily wait for
what
>is running to complete before the next piece of code executes.  If I use
>the following piece of code there is no guarentee that program1
completes
>execution before program2 begins.

>dim x,y
>   x=SHELL("program1")
>   y=SHELL("program2")

>So, what I need to do is make sure program1 executes and is completed
>before program2 activates.  Anyone have any ideas?

Place this in your declarations section
Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Integer)
As Integer

Then do this.

x=SHELL("program1")
do
  If GetModuleUsage(x) = 0 Then exit do
  DoEvents
loop

y=SHELL("program2")
do
  If GetModuleUsage(y) = 0 Then exit do
  DoEvents
loop

FYI
This works by counting the number of usages for a given hInstance (which
is the value returned by the Shell command). When the module usage drops
to zero, the application has ended.  Since the hInstance is only valid
for the copy of the application you are running, it is not affected by
other instances of the same application running.  For example, having
notepad running, then shelling a copy of notepad from your app does not
cause a usage count of two. It instead returns a count of one, which is
your applications copy of notepad.
Finally, the DoEvents is required to keep Windows cooperative
multitasking working.

John



Mon, 08 Dec 1997 03:00:00 GMT  
 Sequential run of DOS program via SHELL command

Quote:


>>I need to run a DOS EXE file and then call a Windows apllication next.  
>>According to what I make of VB use of the SHELL command would look like
>>the way to go on this.  Shell, however, doesn't necessarily wait for
>what
>>is running to complete before the next piece of code executes.  If I use
>>the following piece of code there is no guarentee that program1
>completes
>>execution before program2 begins.

>>dim x,y
>>   x=SHELL("program1")
>>   y=SHELL("program2")

>>So, what I need to do is make sure program1 executes and is completed
>>before program2 activates.  Anyone have any ideas?

>Place this in your declarations section
>Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Integer)
>As Integer
>Then do this.
>x=SHELL("program1")
>do
>  If GetModuleUsage(x) = 0 Then exit do
>  DoEvents
>loop
>y=SHELL("program2")
>do
>  If GetModuleUsage(y) = 0 Then exit do
>  DoEvents
>loop
>FYI
>This works by counting the number of usages for a given hInstance (which
>is the value returned by the Shell command). When the module usage drops
>to zero, the application has ended.  Since the hInstance is only valid
>for the copy of the application you are running, it is not affected by
>other instances of the same application running.  For example, having
>notepad running, then shelling a copy of notepad from your app does not
>cause a usage count of two. It instead returns a count of one, which is
>your applications copy of notepad.
>Finally, the DoEvents is required to keep Windows cooperative
>multitasking working.
>John

I wrote an application that does just this very thing but found a
couple of problems.  I connect a network drive then SHELL the
application on that drive and using GetModuleUsage would wait for the
user to exit the program so I could then disconnect the drive.
However, since the application program was running on the network,
sometimes my program would disconnect the drive before the application
was actually finished exiting..This usually caused a GPF.  So i put a
timer in to wait a couple of seconds.  The other problem is some
larger apps SHELL or EXEC another program that is the actual program
that is running, so your program thinks its done when it isn't..

fyi

-tim

Tim Waters  Systems Programmer
CSC RTI



Tue, 09 Dec 1997 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Help w/Shell command - Sequential Dos Apps

2. Passing drive\dir\filename params to a DOS program via SHELL

3. Run a DOS command and Get output of a DOS command in VB5

4. Running DOS's copy from a shell command in VB

5. Help:Running DOS commands from SHELL function

6. Running DOS Shell in hidden window, or using vb command instead

7. Using Shell Command to Run DOS EXE

8. Dos program Shell command problem

9. Running a DOS program as a Shell (PkUnzip) from VB

10. Running Programs in DOS Shell

11. Dos programs (shell) running in VB5

12. Running a DOS program as a Shell (PkUnzip) from VB

 

 
Powered by phpBB® Forum Software