help with system calls

This is a discussion on help with system calls within the C Programming forums, part of the General Programming Boards category; in my c program i want to make a call to ls,but to store its output as a string without ...

  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,796
    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 10: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,796
    >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, 08:18 AM
  2. Opinions on custom system build
    By lightatdawn in forum Tech Board
    Replies: 2
    Last Post: 10-18-2005, 05:15 AM
  3. Problem With My Box
    By HaVoX in forum Tech Board
    Replies: 9
    Last Post: 10-15-2005, 08: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, 02:08 AM
  5. System Calls && Variables
    By Okiesmokie in forum C++ Programming
    Replies: 6
    Last Post: 03-06-2002, 09:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21