Home > Archive > Unix Programming > October 2005 > giving path to a program file from the process
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
giving path to a program file from the process
|
|
| puzzlecracker 2005-10-16, 6:57 pm |
| hi,
given path a program. can I exec that program from currently running
process or do I have to chdir to it:
example:
I running a program form /home/me and a from it I call exec("/bin/prog
param1 param2") .. will that work?
| |
| Måns Rullgård 2005-10-16, 6:57 pm |
| "puzzlecracker" <ironsel2000@gmail.com> writes:
> hi,
>
> given path a program. can I exec that program from currently running
> process or do I have to chdir to it:
>
> example:
>
> I running a program form /home/me and a from it I call exec("/bin/prog
> param1 param2") .. will that work?
Why don't you try it?
--
Måns Rullgård
mru@inprovide.com
| |
| Gordon Burditt 2005-10-16, 6:57 pm |
| > given path a program. can I exec that program from currently running
>process or do I have to chdir to it:
In general, NO, you don't have to chdir to it. A few programs make
dumb assumptions about where the current working directory is when
they are invoked. This sometimes happens with programs intended
to be run as CGI from a web server.
Most of the time, you don't want to chdir to it. If param1 and
param2 are relative filenames, the invoking program probably thinks
they are relative to *its* current working directory, and the invoked
program will probably think they are relative to its startup current
working directory. If these are different, then something needs
to make param1 and param2 absolute pathnames or otherwise fix them
so they point to the right place.
>example:
>I running a program form /home/me and a from it I call exec("/bin/prog
>param1 param2") .. will that work?
The various forms of exec*() do not take a single string with a
program pathname and arguments in the same string. These are
separate arguments. And there isn't actually a function called
exec().
Gordon L. Burditt
|
|
|
|
|