Read stdout from another program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrbush82
    New Member
    • Jul 2007
    • 2

    #1

    Read stdout from another program

    I am trying to read the standard out of another program into an array or string in my C++ program. I need to read each line individually because based on the output depends on what the program will do.

    Example output of the other program is:
    www.thescripts. com|/|192.168.1.10|7 5.126.163.34|37 281|80|1
    www.thescripts. com|/forum/forum129.html|1 92.168.1.10|75. 126.163.34|3680 4|80|1

    As you can see the data is separated by a "|"(pipe).

    I've been able to get this working in perl, however I need to be able to port it to C++. I've tried and tried but haven't made much success. Any direction would be great.

    Also, I'm doing this in Linux... my goal is to use as portable code as possible... system() does not work as it waits for the command to complete before allowing the program to continue...

    Thanks,
    Jason Bush
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by jrbush82
    I am trying to read the standard out of another program into an array or string in my C++ program. I need to read each line individually because based on the output depends on what the program will do.

    Example output of the other program is:
    www.thescripts. com|/|192.168.1.10|7 5.126.163.34|37 281|80|1
    www.thescripts. com|/forum/forum129.html|1 92.168.1.10|75. 126.163.34|3680 4|80|1

    As you can see the data is separated by a "|"(pipe).

    I've been able to get this working in perl, however I need to be able to port it to C++. I've tried and tried but haven't made much success. Any direction would be great.

    Also, I'm doing this in Linux... my goal is to use as portable code as possible... system() does not work as it waits for the command to complete before allowing the program to continue...

    Thanks,
    Jason Bush

    What is understood is
    you have a program a.exe(for example)
    and you have another program b.exe
    you want to read the output of a.exe inside your b.exe?right
    if yes then you can use
    a.exe | b.exe
    If this is not you wanted thengive me more explanation

    Raghuram

    Comment

    • jrbush82
      New Member
      • Jul 2007
      • 2

      #3
      You are correct. My program (b) would read from the standard out of another program (a). The pipe will work for what I'm doing, I was incorrect in assuming that piping like this did not work in Windows. Since it works in both operating systems, this will work for me! Thanks.

      http://www.microsoft.c om/resources/documentation/windows/xp/all/proddocs/en-us/redirection.msp x?mfr=true

      Comment

      Working...