How to get the printout from a program?

This is a discussion on How to get the printout from a program? within the C++ Programming forums, part of the General Programming Boards category; How do you get the output from a program as a return (or some else way)? Like when calling a ...

  1. #1
    z33z
    Guest

    Question How to get the printout from a program?

    How do you get the output from a program as a return (or some else way)? Like when calling a program with either exec() or system(), and then get back the printout from that program, not just it's returnvalue.

    Like "system("ls")" and get what the result the result of the ls command, not just zero or non zero...

    Using unix, but want to know how you do in dos too...

  2. #2
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hi,

    If i understand you correctly i think you want to catch everything that a program outputs. For example say you run ls.exe from system(). and it writes on the screen "Hello from program" i think you want your program to get that.

    If thats right then you look how its done from a dos prompt:

    c:\>copy >> file.txt

    This saves what the copy program makes up into c:\file.txt.

    So to do this from your program:

    system("copy >> file.txt");

    that does the same as from the prompt. Then you have the output in the file, so you just need to read the file into a buffer for use by your program, i would then sugest deleteing file.txt, from your program.

    Hope that helps.

    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  3. #3
    z33z
    Guest
    I know, but that seemed like a very stupid way of doing it...

  4. #4
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    you might want to look into pipes.
    i'm still unclear on what exactly you're trying to do. but if i'm guessing right i think you want to use pipes.

  5. #5
    z33z
    Guest
    How exactly does it work with pipes? Does it come as an argument to the program then?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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