Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
How to change display settings: screen resolution, screen refresh rate
Enumerating printer drivers installed
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
Custom GDI+ class
How to retrieve information about a cache entry (Internet Explorer)
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to display Windows On-Screen Keyboard
How to convert a bitmap file to monochrome format (1 bpp)
Custom HttpRequest class (WinINet)
How to print FoxPro form
Custom HttpRequest class (WinHTTP)
Using EnumPrinters function to enumerate locally installed printers
Windows Shell Icons displayed and exported to ICO files (Vista)
How to activate Windows Calculator
Using WM_COPYDATA for interprocess communication (VFP9)
How to create MD-5 and SHA-1 hash values from a string
Winsock: sending email messages (SMTP, port 25)
How to set Creation Date/Time for a folder (WinNT)
Mapping and disconnecting network drives
How to detect if additional monitor is connected and active
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
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
     
      Buy this example for $10.00
    Instant email delivery.

    Read more...
     


    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    7232 bytes  
    Created: 2004-12-18 09:14:35  
    Modified: 2013-09-20 13:26:56  
    Visits in 7 days: 57  
    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-2014 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.68), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.87.88.52)
    57 sec.Function: 'PlaySound'
    Function group: 'Windows Multimedia'
    2.33 min.Function: 'mmioWrite'
    Function group: 'Windows Multimedia'
    6.82 min.Function: 'GetFullPathName'
    Function group: 'File Management'
    2 day(s)Function: 'CryptProtectData'
    Function group: 'Cryptography Reference'
     Function: 'InternetCrackUrl'
    Function group: 'Internet Functions (WinInet)'
     Example: 'Displaying the main Dial-Up Networking dialog box'
     Example: 'Retrieving information specific to the current Time Zone'
     Function: 'DeleteFileTransacted'
    Function group: 'File Management'
     Function: 'waveOutSetVolume'
    6 day(s)Function: 'MonitorFromWindow'
    Google
    Advertise here!