ID: Q131621
The information in this article applies to:
By using the FOXTOOLS.FLL library that ships with FoxPro, you can execute an MS-DOS command or program without seeing the "FoxPro Run Command" window or another MS-DOS session. This is done by registering and calling the Windows API WinExec() function as demonstrated in this article.
The following program creates a sample function that executes an MS-DOS command or program and keeps the MS-DOS window hidden. The program takes one parameter, the command to be executed.
To maintain control over the MS-DOS window, the program sends the command through a PIF file. To keep this window hidden, use the Windows PIF Editor to make the following changes to the PIF file you use (this example uses FOXRUN.PIF in the FoxPro directory):
1. Select the "Close Window on Exit" check box.
2. Set "Display Usage" to "Windowed."
*-------------------- RUN.PRG ----------------------- * Sample program to Execute an MS-DOS command and keep * the MS-DOS window hidden. * * To use this function in FoxPro to create a new directory, * use one of the following two commands that illustrate two * ways to call the function and achieve the same result: * * =RUN("MD C:\FPW26\TESTDIR") * * DO RUN WITH "MD C:\FPW26\TESTDIR" *
FUNCTION run PARAMETER doscmd
SET LIBRARY TO SYS(2004)+"foxtools.fll" ADDITIVE
winexec = REGFN("WinExec", "CI", "I")
* To have control over the visibility of the * MS-DOS command, call it through a PIF file.
* IMPORTANT: (1) Be sure the "Close Window on Exit" check box in * in the PIF file is selected. (2) Be sure "Windowed" is the * selected "Display Usage."
cmdstart = SYS(2004)+"FOXRUN.PIF /C "
* Now concatenate the 2 pieces of the command:
fullcmd = cmdstart + doscmd
retval = CALLFN(winexec, fullcmd, 0)
RELEASE LIBRARY SYS(2004)+"foxtools.fll"
Additional reference words: 2.60a FoxWin KBCategory: kbprg kbcode KBSubcategory: FxprgFoxtools
Last Reviewed: September 14, 1995