Re: system() function



On 2007-03-21, gio <giorginooo.rossi@xxxxxxxx> wrote:
I have a problem and the solution should works under windows and unix
OS.

Suppose I have a program ex.c in the directory X (so the current
working directory of ex.c is X).

Also suppose I have this code fragment:
...
char otherpath[PATHLEN];
char cmd[CMDLEN];
...
...
otherpath="Y" //where y is a valid path string
...
system(cmd); //where cmd is any command string
...

If in cmd is specified a relative path, it is relative to the current
working directory(in this example is X).

There is a way to execute command wich paths are relatives to the
"otherpath" variable (in this example is Y)?

chdir(otherpath);
system(cmd);
chdir(getenv("PWD")); // optional: change back...




--

Bye.
Jasen
.



Relevant Pages