home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!portal!dfuller
- From: dfuller@portal.hq.videocart.com (Dave Fuller)
- Subject: Re: passing variables to system() ?
- Message-ID: <C0rDo7.1n7@portal.hq.videocart.com>
- Organization: VideOcart Inc.
- X-Newsreader: Tin 1.1 PL3
- References: <apwhite.726840479@unix1.tcd.ie>
- Date: Tue, 12 Jan 1993 20:45:43 GMT
- Lines: 37
-
- apwhite@unix1.tcd.ie (Andrew White) writes:
- : Hi There,
- : I have a C program written in which I want to call another program (written in
- : awk), passing that program a variable -ie (awkprog x=variable filename) is there
- : a way I can do this with system() or is it a bit more complicated than that??
- :
- : BTW Yes, I do need to call the program , I am not going to use C for field
- : matching etc.
- :
- :
- : Thanks
- : Andrew.
- :
-
- Create the command ahead of time, then pass to system.
-
- char xvar[20]; /* these are all arbitrary sizes, use a better method */
- char file[20];
- char syscall[50];
-
- strcpy(file, "testfile");
- strcpy(xvar, "find"); /* i assume that you want to pass a command line
- that looks like
- awkprog text file
- */
- /* file and xvar can be any char pointer, i just set them up this way
- for an example. All you are probably concerned with are the next 2 lines
- */
-
- sprintf(syscall, "awkprog %s %s", xvar, file);
- system(syscall); /* you should always check return values from system */
-
- That should do it.
-
- Dave Fuller
- dfuller@portal.hq.videocart.com
-
-