#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Rochester, NY
    Posts
    21
    Rep Power
    0

    Talking Question about system()


    Say I make a call like:

    system(string);

    How do I get the output of the program I'm calling from the command line.

    Thanks.
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    easiest way would be to send the output of the program to a file and then read the file.
    i.e.
    system("c:\your_program.exe > results.txt");

    then open and read results.txt
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Rochester, NY
    Posts
    21
    Rep Power
    0
    Cool thanks man, I'll do that.

    I can specify the whole path, right?

    Like c:\your_program.exe > c:\webdocs\results.txt
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    yep
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    Be aware that a backslash also serves as an escape which allows you to insert special characters into a string, the most common one being the newline '\n'. In order for it to be read as a backslash, you need to enter two backslashes; eg: "c:\\your_program.exe > c:\\webdocs\\results.txt"

    Another way to read the output of a command is through a pipe with popen(), which also replaces the system() call. popen will open a stream that you can handle and read almost exactly like a text file. As I recall, the only special things are opening it with popen and closing it with pclose.

IMN logo majestic logo threadwatch logo seochat tools logo