home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19616 < prev    next >
Encoding:
Text File  |  1993-01-12  |  1.5 KB  |  49 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!portal!dfuller
  3. From: dfuller@portal.hq.videocart.com (Dave Fuller)
  4. Subject: Re: passing variables to system() ?
  5. Message-ID: <C0rDo7.1n7@portal.hq.videocart.com>
  6. Organization: VideOcart Inc.
  7. X-Newsreader: Tin 1.1 PL3
  8. References: <apwhite.726840479@unix1.tcd.ie>
  9. Date: Tue, 12 Jan 1993 20:45:43 GMT
  10. Lines: 37
  11.  
  12. apwhite@unix1.tcd.ie (Andrew White) writes:
  13. : Hi There,
  14. :   I have a C program written in which I want to call another program (written in
  15. : awk), passing that program a variable -ie (awkprog x=variable filename) is there
  16. : a way I can do this with system() or is it a bit more complicated than that??
  17. : BTW Yes, I do need to call the program , I am not going to use C for field 
  18. : matching etc. 
  19. : Thanks
  20. : Andrew.
  21.  
  22.   Create the command ahead of time, then pass to system.
  23.  
  24. char xvar[20];      /* these are all arbitrary sizes, use a better method */
  25. char file[20];
  26. char syscall[50];  
  27.  
  28. strcpy(file, "testfile");
  29. strcpy(xvar, "find");  /* i assume that you want to pass a command line
  30.                           that looks like   
  31.                           awkprog text file
  32.                        */
  33. /*  file and xvar can be any char pointer, i just set them up this way
  34.     for an example. All you are probably concerned with are the next 2 lines
  35. */
  36.  
  37. sprintf(syscall, "awkprog %s %s", xvar, file);
  38. system(syscall);   /*  you should always check return values from system */   
  39.  
  40. That should do it.
  41.  
  42. Dave Fuller
  43. dfuller@portal.hq.videocart.com
  44.  
  45.