TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Lars Hellsten
from: Mike Bilow
date: 1996-01-31 18:03:30
subject: Executing a program?

Lars Hellsten wrote in a message to All:

 LH> DosExecPgm seems to work fine for running OS/2 applications
 LH> (and shelling to CMD.EXE), but I take it I can't use it to
 LH> execute a DOS program.  I'vee taken a look at
 LH> DosStartSession, but the problem with that, is that it
 LH> starts a new session and then resumes the current session
 LH> right away.  I don't want my program to resume until the
 LH> program being executed has finished - how would I go about
 LH> doing this?  I've tried having the program create batch
 LH> files and run them with DosExecPgm, but that doesn't seem to
 LH> work too well either.

Call DosExecPgm() on CMD.EXE, and pass it a command line with a
"/C" switch and your program name and arguments, as in
"CMD.EXE /C MYPROG.EXE ARG1 ARG2". There are more elegant
solutions, but this is actually the only reliable way to synchronously
execute batch (BAT or CMD) files at all.

 LH> So, to sum it up, I'm trying to have my program run an
 LH> external program that could be either DOS or OS/2 native,
 LH> and wait for the program to  finish executing before my
 LH> program continues.  I'm using Virtual Pascal for OS/2 ...
 LH> can anyone plese explain how I'd do this?  

I can't speak for Pascal, but the technique I describe has been working in
my released C code for years.  This is how my MUTEX utility works, for
example, although MUTEX is a little smarter and reads the name of the
program out of the environment (OS2_SHELL) rather than assuming CMD.EXE. 
Howeevr, MUTEX calls the OS/2 API directly for all of this stuff, and does
not go through the C run-time library.
 
-- Mike


--- 
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)
SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 323/107 170/400 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.