home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / programm / 5229 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.6 KB  |  68 lines

  1. Path: sparky!uunet!mcsun!Germany.EU.net!nixpbe!uranium!uranium!not-for-mail
  2. From: Josef Moellers <mollers.pad@sni.de>
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: How to execute unix commands from a c-program
  5. Date: 6 Nov 1992 12:31:44 +0100
  6. Organization: Siemens Nixdorf Informationssysteme AG, Paderborn, Germany
  7. Lines: 56
  8. Sender: josef@uranium.sto.pdb.sni.de
  9. Message-ID: <1ddl30INNet2@uranium.sto.pdb.sni.de>
  10. References: <1992Nov4.153029.21837@cs.ruu.nl> <1992Nov4.163532.8801@cbfsb.cb.att.com>
  11.  
  12. In <1992Nov4.163532.8801@cbfsb.cb.att.com> nll@cbnewsb.cb.att.com (neal.l.leitner) writes:
  13.  
  14. >From article <1992Nov4.153029.21837@cs.ruu.nl>, by hpverwei@cs.ruu.nl (Dick Verweij):
  15. >> See subject,
  16. >> 
  17. >> -- 
  18. >> DICK H.P. VERWEIJ
  19. >> 
  20. >> --------------------------------------------------------------------------------
  21. >> D:-) I:-) C:-) K:-) email : hpverwei@cs.ruu.nl 
  22. >main()
  23. >{
  24. >      .
  25. >      .
  26. >      .
  27. >      system("ls -l");
  28. >}
  29.  
  30. >or
  31.  
  32. >main()
  33. >{
  34. >      char mystring[10];
  35. >      .
  36. >      .
  37. >      .
  38. >      strcpy(mystring,"ls -l");
  39. >      system(mystring);
  40. >}
  41.  
  42. or
  43. main()
  44. {
  45.     .
  46.     .
  47.     .
  48.     switch (fork())
  49.     {
  50.     case 0: /* child */
  51.         execlp("ls", "ls", "-l", NULL);
  52.         perror("ls");
  53.         exit(1);
  54.     case -1: /* Error */
  55.         perror("fork");
  56.         break;
  57.     default: /* parent */
  58.         /* You can wait() here */
  59.         break;
  60.     }
  61. }
  62.  
  63. This saves the overhead of firing up Your shell, as done by system()!
  64. -- 
  65. | Josef Moellers        | c/o Siemens Nixdorf Informationssysteme AG  |
  66. |  USA: mollers.pad@sni-usa.com    | Abt. STO-XS 113       | Riemekestrasse   |
  67. | !USA: mollers.pad@sni.de    | Phone: (+49) 5251 835124 | D-4790 Paderborn |
  68.