Partager via


RUN | ! Command

Executes external operating commands or programs.

RUN [/N] WindowsCommand | ProgramName

! [/N] WindowsCommand | ProgramName

Parameters

  • WindowsCommand
    Specifies a Windows executable command to execute.

  • ProgramName
    Specifies the Windows program or application to run.

  • /N
    Specifies NOWAIT. Include /N to execute another Windows-based application.

Remarks

You can issue RUN from within the Command window or from within a program.

Note

To use RUN, Command.com or Cmd.exe must be located where the COMSPEC environment variable can find it.

Warning

Do not use RUN to run disk reorganization programs such as CHKDSK from within Visual FoxPro. These programs modify the contents of your disk in a manner that may prevent Visual FoxPro from operating properly.

RUN and Visual FoxPro

The RUN command (without /N parameter) uses the following sequence order to determine which program to use when executing the specified RUN command:

  • Named PIF file - if the program you specify in RUN does not have an extension, Visual FoxPro first looks for a Program Information File (PIF) with the name you specify. If the PIF file is found, the program specified in the PIF is executed with the PIF parameters.

  • FOXRUN.PIF file - if a Named PIF file can not be found, the RUN command searches for the default Foxrun.pif file. If this file is found, the program specified in Foxrun.pif is executed with the PIF parameters.

  • COMSPEC Environment Variable - if no PIF file is found which meets the above criteria, the RUN command uses the SHELL program specified by the Windows operating system COMSPEC environment variable. This variable typically points to Cmd.exe, however, in older operating systems such as Windows 98, it will point to Command.com.

Note

For Visual FoxPro 9, the Foxrun.pif file is no longer installed in the Visual FoxPro root directory so that it is no longer used by default. The default behavior for Visual FoxPro 9 is that a RUN command (without /N parameter) should use the SHELL program specified by the COMSPEC environment variable. Foxrun.pif is now installed in the Visual FoxPro Tools directory if needed.

A PIF lets you run other programs under Windows. You can specify parameters for the program, such as whether the program is run in a window or on the full screen, the amount of memory allocated for the program, and so on.

If intended to be used, Foxrun.pif must be in the same directory as VFPVersionNumber.exe where VersionNumber represents the version number of this release of Visual FoxPro.

Unless needed, a PIF file should be avoided since the RUN command automatically use Command.com to call the program specified in the PIF file. For example, if your PIF file specified Cmd.exe as the program to run, Visual FoxPro would actually have Command.com call Cmd.exe to execute the specified RUN command, which may not be the desired behavior. It is preferable to have the RUN command directly use the SHELL program specified by the operating system's COMSPEC environment variable.

Note

With Windows XP, you can view and edit the COMSPEC environment variable by right-clicking on your computer desktop's My Computer icon and selecting the Properties dialog box (Advanced tab).

/N

/N means NOWAIT. Include the letter N to execute another Windows-based application and return control immediately to Visual FoxPro. For example, the following statement opens the Windows Character Map accessory:

! /N CHARMAP.EXE 

The following example opens the Windows Display Properties dialog box:

! /N CONTROL COLOR

A Windows-based application executed with RUN /N or ! /N behaves the same way the application does when you open it through the Windows Explorer or by selecting Run from the Start menu. You can switch between the application and Visual FoxPro or FoxPro for Windows using the standard Windows operations.

You can include an optional numeric value immediately after /N to specify how the Windows-based application is opened. Do not include any spaces between /N and the numeric value. The following table lists the numeric value you can include and describes the state of the Windows-based application when opened.

Value

Application attributes

1

Active and normal size.

2

Active and minimized.

3

Active and maximized.

4

Inactive and normal size.

7

Inactive and minimized.

Running External Programs in Visual FoxPro

By default, Foxrun.pif runs the specified external program in a window. In Visual FoxPro, the FoxPro Run Command window is closed after the external program or command is finished executing.

You can use the Windows PIF editor to customize Foxrun.pif. You can edit the PIF to specify if the Inactive FoxPro Run Command window is left open or is closed (the default in Visual FoxPro) with the Close Window on Exit check box. You can also open external programs in a full screen by selecting Full Screen; allocate memory for the program; and so on.

Windows 2000 Logo Certification

If you plan to submit your application for Windows Logo certification, you should not use the RUN command because it can potentially violate the System Group Policy requirements. Instead, you should use DECLARE DLL with ShellExecuteEx.API.

See Also

Reference

GETENV( ) Function

_SHELL System Variable

Other Resources

Commands (Visual FoxPro)