Re: system() function
- From: Josef Moellers <josef.moellers@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Mar 2007 14:44:00 +0100
gio 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)?
Build a new cmd, e.g.:
char *newcmd = malloc(3+strlen(otherpath)+2+strlen(cmd)+1);
sprintf(newcmd, "cd %s; $s", otherpath, cmd);
then run that command:
system(newcmd);
free(newcmd);
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
.
- Follow-Ups:
- Re: system() function
- From: gio
- Re: system() function
- References:
- system() function
- From: gio
- system() function
- Prev by Date: system() function
- Next by Date: Re: system() function
- Previous by thread: system() function
- Next by thread: Re: system() function
- Index(es):
Relevant Pages
|