Thread: help with system calls

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    2

    help with system calls

    in my c program i want to make a call to ls,but to store its output as a string without displaying it as stdin..ne suggetions?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Use a pipe:
    Code:
    /* Potential example */
    FILE *pin = popen("ls", "r");
    char buffer[BIG_ENOUGH];
    int i, c;
    
    while ((c = fgetc(pin)) != EOF)
      buffer[i++] = (char)c;
    
    pclose(pin);
    Last edited by Prelude; 06-06-2005 at 09:42 AM.
    My best code is written with the delete key.

  3. #3
    FOX
    Join Date
    May 2005
    Posts
    188
    popen() instead of fopen() maybe?

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    2
    Quote Originally Posted by ^xor
    popen() instead of fopen() maybe?
    thanx..that helped..

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >popen() instead of fopen() maybe?
    Force of habit, thanks for the heads up.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic system calls help.
    By AmbliKai in forum C Programming
    Replies: 5
    Last Post: 03-21-2008, 07:18 AM
  2. Opinions on custom system build
    By lightatdawn in forum Tech Board
    Replies: 2
    Last Post: 10-18-2005, 04:15 AM
  3. Problem With My Box
    By HaVoX in forum Tech Board
    Replies: 9
    Last Post: 10-15-2005, 07:38 AM
  4. School Mini-Project on C/C++ (Need Your Help)..
    By EazTerence in forum C++ Programming
    Replies: 4
    Last Post: 09-08-2005, 01:08 AM
  5. System Calls && Variables
    By Okiesmokie in forum C++ Programming
    Replies: 6
    Last Post: 03-06-2002, 09:10 PM