Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Converting Unicode data from the Clipboard to a character string using a given code page
How to download a file from the FTP server using FtpGetFile
Detecting changes in connections to removable drives (VFP9)
Enumerating data formats currently available on the clipboard
Winsock: sending email messages (SMTP, port 25)
How to play AVI file on the _screen
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Custom FTP Class for Visual FoxPro application
Custom HttpRequest class (WinHTTP)
Deleting files into the Recycle Bin
Creating the Open dialog box to specify the drive, directory, and name of a file to open
How to activate Windows Calculator
Splash Screen for the VFP application
Custom HttpRequest class (WinINet)
Using Font and Text functions
Establishing connection using the SQLDriverConnect
How to display the Properties dialog box for a file (ShellExecuteEx)
Mapping and disconnecting network drives
Displaying bitmap using the AlphaBlend function
Dragging files from Explorer window and dropping them on FoxPro control (requires VFP9)
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
The following class allows to run a set of MSDOS commands and get back a response as a string. The MSDOS window is present but not visible.

This is how the class can be tested from the VFP Command Window:



If CreateMsdosSession method returns True, then RunCommand method can be used to launch msdos commands. An output of the command processor is collected in a buffer. GetResponse method returns the content and clears the buffer.

Use this program code to test the class:

LOCAL cmd As msdos, cResponse
cmd = CREATEOBJECT("msdos")

IF NOT cmd.createmsdossession()
        ? "CreateMsdosSession call failed."
        RETURN
ENDIF

cmd.runcommand("dir *.bmp")
cmd.runcommand("ipconfig")
= INKEY(2) && gives MSDOS some time to return

cResponse = cmd.getresponse()
STORE cResponse TO _cliptext && for reviewing later

SET MEMOWIDTH TO 120
? cResponse

The INKEY() is here to provide some time for the command processor to generate an output. The WaitForSingleObject API, which could be an ideal solution, does not wait for a console output. May be the Timer object can do better than the INKEY() does.

See also:
  • Running external applications from VFP using WinExec
  • Using ShellExecute for performing operations on files
  • Running external applications from VFP using CreateProcess
  • Running an external program from FoxPro and waiting for its termination
  • Creating a console window for Visual FoxPro application
  •  
      Members area. Log in to view this example.
     
      User name:
      Password:
     
     
      Forgot your password?
     
      Sign up for
    the Membership
     
     


    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    7232 bytes  
    Created: 2004-12-18 09:14:35  
    Modified: 2011-12-10 09:20:22  
    Visits in 7 days: 164  
    Listed functions:
    CloseHandle
    CreatePipe
    CreateProcess
    DuplicateHandle
    GetCurrentProcess
    GetFileInformationByHandle
    GetSystemDirectory
    ReadFile
    TerminateProcess
    WriteFile
    Printer friendly API declarations
    My comment:
    The VFP class starts the command processor (cmd.exe) as a child process using the CreateProcess. Through input parameters for this call the standard input and output handles of the child process are redirected to two anonymous pipes.

    The msdos window is put in a hidden state by placing STARTF_USESHOWWINDOW in STARTUPINFO structure. So the usual black msdos window does not blink and does not appear in the Task Bar.

    Though it has an unexpected effect:

    cmd.RunCommand("C:\myprog.exe")


    The code line above will start myprog.exe and place it in a hidden state. Only after the cmd object is released, the myprog.exe becomes visible and appears in the Task Bar.

    * * *
    Through one pipe the command processor receives commands (RunCommand method). The other pipe is used to get an output generated by the command processor (GetResponse method).

    An anonymous pipe is an unnamed, one-way pipe that typically transfers data between a parent process and a child process.

    This is like a temporary file that is shared by two processes. One of these processes can write to the pipe, and the other one can read from the pipe, which is what "one-way" means.

    MSDN links:

  • Creating a Child Process with Redirected Input and Output -- the FoxPro class above actually uses a translation of a large part of this C code

  • How To Spawn Console Processes with Redirected Standard Handles
  • Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    A.M. | 2006-10-10 14:04:47
    Does not return output when tested under W2K 5.00.2195
    John Clarke | 2007-12-18 20:06:32
    I'm not sure how to terminate grand-child process. If CMD.EXE (child) launches an application (grand-child) that takes a long time to run, I'd like to be able to handle a timeout on that process. I wonder if there is a way to retrieve the process handle for the app that we send in WriteToPipe(cCommand...). If so, we could use the WaitForSingleObject() API to trap for timeouts.

    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (23.20.196.179)
    4 sec.Function: 'SetSystemPowerState'
    Function group: 'Power Management'
    4.65 hrs.Example: 'Shortcut Menu Class'
     Function: 'DrawFrameControl'
    Function group: 'Painting and Drawing'
    5.34 hrs.Example: 'How to change display settings: screen resolution, screen refresh rate'
    5.35 hrs.Function: 'GetComputerObjectName'
    9.5 hrs.Example: 'HOWTO: Use the Win32 API to Access File Dates and Times'
     Example: 'Accessing the list of Windows Recent Documents'
    16.74 hrs.Example: 'How to find the application associated with a file name'
     Function: 'CreateDirectory'
    18.6 hrs.Function: 'UuidToString'
    Function group: 'Remote Procedure Call (RPC)'
    Google
    Advertise here!