Appending environment variable to system calls...

Jonathan W Miner jwm712 at unhd.unh.edu
Tue Apr 2 09:59:53 AEST 1991


In article <22200 at yunexus.YorkU.CA> racine at yunexus.yorku.ca (Jeff Racine) writes:
>I wish to be able to set an environment variable (the path to a file)
>and then to execute a program using the system() function in the
>following fashion:
>
>	char *s;
>	s=getenv("FOO");
>	system("FOO/FUBAR");
>
> [ stuff deleted ]
>Jeff Racine        
>racine at nexus.yorku.ca   
>racine at yunexus.UUCP

        The following may do what you want:

        char *s;
        char temp[256];
        s=getenv("FOO");
        sprintf(temp,"%s/FUBAR",s);
        system(temp);

Better ways probably exist, take a look at the exec functioins.
Jon.

        


-- 
Jonathan Miner        | I don't speak for UNH, and UNH does not 
jwm712 at unhd.unh.edu   | speak for me! 
(603)868-3416         | Hacking to survive......



More information about the Comp.lang.c mailing list