Results 1 to 4 of 4

Thread: Executing External Applications using Exec

  1. #1

    Executing External Applications using Exec

    System: WinXP
    Language: Pascal
    OOP: No
    Compiler/IDE: FPC
    Libraries/API: None.

    Update:
    Even though there are spaces in the path to my exe, it doesn't change anything, as I ran it from C:\ and it still didn't do it. (Yes, I moved the text file with it).

    OK, well, after much experimenting, I found:
    http://freepascal.org/docs-html/rtl/dos/exec.html

    I knew about this before, but this means basically to call an external app, I do this:

    [pascal]
    SwapVectors; {Not sure why, but I do remember this being used before..}
    Exec(path,com); {Path to file, then commands to be run on the file...}
    SwapVectors;
    [/pascal]

    However, when I run this code:
    [pascal]
    SwapVectors;
    Exec('time.txt','');
    SwapVectors;
    readln;
    [/pascal]
    It doesn't run the app, but it waits on the readln... I'm confused. What do I need to do?

    Or, is there another, just as easy way to do this?
    --MagicRPG--

  2. #2

    Executing External Applications using Exec

    On Win32 platform you can use ShellExecute() from Win32 API to run the application, e.g.:
    Code:
     // hWindow is the handle of your app's window
     ShellExecute(hWindow, 'open', 'c:\Windows\cmd.exe', nil, nil,
      SW_SHOWNORMAL) ;

  3. #3

    Executing External Applications using Exec

    You can also use TProcess from "process" unit. While it's piping mechanism is broken (i.e. you cannot get the program output using it), the non-piped mode works just fine. You can control if your program should wait for it, or run it in parallel.

    But if the called process uses something like ReadLn, there is no help.

  4. #4

    Executing External Applications using Exec

    Well, with messing around, I made:
    [pascal]
    ShellExecute(hwindow, 'open', 'openal.txt', nil, nil, SW_SHOWNORMAL) ;
    readln;
    [/pascal]
    work. Couldn't figure out what unit to use, so I randomly started testing some, and found Windows was what I needed. This should help
    --MagicRPG--

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •