#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Belgium
    Posts
    60
    Rep Power
    12

    how to execute a programme within a programme ?


    How do I execute a programme within a C programme ?
    any good docs articles on this ?
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,143
    Rep Power
    2222
    NAME
    system - execute a shell command

    SYNOPSIS
    #include <stdlib.h>

    int system(const char *string);

    DESCRIPTION
    system() executes a command specified in string by calling
    /bin/sh -c string, and returns after the command has been
    completed. During execution of the command, SIGCHLD will
    be blocked, and SIGINT and SIGQUIT will be ignored.

    RETURN VALUE
    The value returned is -1 on error (e.g. fork failed), and
    the return status of the command otherwise. This latter
    return status is in the format specified in wait(2).
    Thus, the exit code of the command will be WEXITSTA-
    TUS(status). In case /bin/sh could not be executed, the
    exit status will be that of a command that does exit(127).
    If you are using a DOS/Windows C compiler, it should also have implemented system(). Just read the help file/documentation on it.

    When you use system(), the calling process is still there and can check the status returned by the system() call.

    However, if you want to have the called program replace the calling program, then look into the exec* family of functions.
  4. #3
  5. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    I recall reading a few weeks ago that the system command is VERY slow. Be sure to read the documentation like dwise1_aol suggested. I think it provides an alternative.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,143
    Rep Power
    2222
    The man page on Linux also mentions some gotcha's regarding signals, I think. It didn't apply to what I was doing, so I didn't pay much attention.

    And don't just read the documentation, but also write some test code.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    25
    Rep Power
    0
    You can use shell execute to run a program from within a program. For documentation, visit http://msdn.microsoft.com/library/de...ellexecute.asp


    ShellExecute(NULL,
    "open",
    "C:\\Program Files\\Internet Explorer\\iexplore.exe",
    NULL,
    NULL,
    SW_SHOW)
  10. #6
  11. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    jason i noticed u said system is very slow? what about execve?
  12. #7
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,143
    Rep Power
    2222
    Originally posted by infamous41md
    jason i noticed u said system is very slow? what about execve?
    In both Windows and Linux, execve would replace the calling program. In Linux we'd couple it with a fork, but Windows doesn't do forks -- there's CreateProcess which works quite differently.

    However, Jason_G never replied, so we don't know what OS he's running or whether exec* would work for him or not.

IMN logo majestic logo threadwatch logo seochat tools logo