Thread: System Commands Output

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    2

    System Commands Output

    I want to save the output of system command in the memory location.For example the following command will save the output in the file /tmp/lsfile.txt.

    system("ls -al > /tmp/lsfile.txt");

    Rather than saving it in file is it possible to save it in some string variable or any other data structure?Does any on know?

  2. #2
    muttski
    Guest
    There probly is, but if you want a temporary solution just load the file.

  3. #3
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    Yes there is. try this:
    Code:
    FILE *fp;
    
    fp=popen("ls -al", "r");
    
    /* read from "fp" using f***-functions */
    
    pclose(fp);
    alex

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. System commands
    By Tropicalia in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2006, 11:18 AM
  2. retrieve output from system()
    By mmongoose in forum C++ Programming
    Replies: 5
    Last Post: 12-15-2005, 06:44 AM
  3. system commands. deletion of file after program terminates
    By xddxogm3 in forum C++ Programming
    Replies: 12
    Last Post: 11-24-2003, 10:41 PM
  4. string variables and system commands part 2
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-25-2001, 12:57 AM
  5. string variables in system commands
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-24-2001, 12:36 PM