Beginner's question: How to redirect shell's standard output into program's stream?

This is a discussion on Beginner's question: How to redirect shell's standard output into program's stream? within the C++ Programming forums, part of the General Programming Boards category; Hi, this is a beginners question, I appreciate you taking the time to help me out. The motivation: I want ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    11

    Beginner's question: How to redirect shell's standard output into program's stream?

    Hi, this is a beginners question, I appreciate you taking the time to help me out.

    The motivation:
    I want to take the standard output of a shell command (in Red Hat, using tcsh, in my case) and redirect it into my program for processing.

    (Then ideally I would love to take the output of my program and redirect it to yet another command, but this is a second issue.)

    Simple example:

    I naively thought this might work:

    I want to type this on the shell:

    Code:
    $ echo Harry > hello
    and I was expecting this output on my terminal:

    Code:
    $ hello, Harry
    And this would be my simple hello program:

    Code:
    #include <iostream>
    #include <string>
    
    int main() {
      std::string usrInput;
      std::cin >> usrInput;
      std::cout << "hello, " << usrInput << std::endl;
      return 0;
    }
    Thank you very much for your help!

  2. #2
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    Last edited by SirPrattlepod; 10-04-2013 at 08:58 PM.

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    11
    Thank you so much. Funny, I was sure I had tested both > and | . Will read more on those operators, thank you!

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    11
    And for other begginers looking at this thread, check this out:
    Code:
    echo Harry > hello
    will write "Harry" to the file hello (and that is when the hello file ceases to be the compiled program and becomes an ordinary text file ;-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-11-2011, 10:40 AM
  2. Where does the standard output go the following program
    By Overworked_PhD in forum Linux Programming
    Replies: 1
    Last Post: 02-23-2009, 07:48 PM
  3. Shell output into program during runtime
    By evilkillerfiggi in forum Linux Programming
    Replies: 3
    Last Post: 08-03-2006, 10:50 AM
  4. redirect C output to shell (bash) input
    By deltaxfx in forum C Programming
    Replies: 7
    Last Post: 08-24-2005, 01:55 PM
  5. how to redirect the output of a program?
    By dkt in forum C Programming
    Replies: 2
    Last Post: 04-25-2002, 12:05 AM

Tags for this Thread


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