#1
  1. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0

    Calling another program


    Have a question...

    How do you call another .exe from within a command line program so that I can pass it parameters?

    Eric
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    USA
    Posts
    286
    Rep Power
    13
    CreateProcess() ought to do it.
    Jon Sagara

    "Me fail English? That's unpossible!"
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    you can use the imho easier function ShellExecute from shell32.dll.
    the syntax (from the MS Windows SDK) is:
    Code:
    HINSTANCE ShellExecute(
        HWND hwnd,	// handle to parent window
        LPCTSTR lpOperation,	// pointer to string that specifies operation to perform
        LPCTSTR lpFile,	// pointer to filename or folder name string
        LPCTSTR lpParameters,	// pointer to string that specifies executable-file parameters 
        LPCTSTR lpDirectory,	// pointer to string that specifies default directory
        INT nShowCmd 	// whether file is shown when opened
       );
    [edit]
    the only thing that was unclear to me first was "lpOperation" which should be "open"
    [/edit]
    Last edited by M.Hirsch; November 8th, 2002 at 01:10 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    12
    A portable solution would be to use popen, which allows complete command line option passing. It's generally part of stdio.h in modern compilers. As a bonus the input and output are available to the calling program.

    If you want the program to present it's interface to the end user, the aforementioned CreateProcess is the way to go.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  8. #5
  9. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0
    Thanks guys. I'll try to get working on these tonight if I can scrape time away from my daughter.

    Eric

IMN logo majestic logo threadwatch logo seochat tools logo