exec

Gamma: Version 4.0
Prev |  | Next

# `exec`

`exec` -- executes a program.

## Syntax

    exec (program, arguments?...)

## Arguments

`program`

  The name of a program to execute, as a string.

`arguments`

  The arguments to the program, each as a string.

## Returns

Does not return if successful, or -1 if an error occurs.

## Description

This function is a binding for the C function `execvp`, which causes the interpreter to terminate immediately, and to run the named program in its place. The "p" in the `execvp` function indicates that a search is made for the named executable in the current path, as defined by the PATH shell variable. Unlike the C `execvp` function, the first argument in Gamma's `exec` function does not repeat the program name--it is automatically inserted for you.

## Example

        Gamma> exec("/bin/ls","-l","/usr/bin");
        -rwxr-xr-x    1 root     root        98844 Aug  7  2000 a2p*
        -rwxr-xr-x    1 root     root         4080 Jul 19  2000 access*
        -rwxr-xr-x    1 root     root        10256 Jul 12  2000 aclocal*
        ...

(does not return)

See the Starting Programs section of the Common Functions chapter (Tutorial One), or the Start a Process section of the Common Functions for Any Program (Tutorial Two) chapter in the Cogent Tools Demo and Tutorials book for examples of this function used in context.

## See Also

`fork`, `wait`

Prev | Home | Next
`errno` | Up | `exit_program`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.