Thread: How to Pipe?

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    How to Pipe?

    I recently heard of a C++ function called piping - sending a .txt to an .exe. I Couldn't find anyonr that knew how to do it. If someone does - could they post a basic version of it? thanks.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    I've never heard of a specific C++ process of piping that has to do with sending a .txt to a .exe, but that doesn't mean there is one.

    The term piping simply means to pass data through a function or process and get a result. Think back at algebra where you pass the domains of a function through the function to get the range.

    So to say that you want to "send a .txt to a .exe" with the term piping in the same sentence, only leads me to ask, what do you want the .exe to do to the .txt? Regardless of the answer to this question, you'll inevitably start off looking at File I/O. There is a section in the Cprogramming.com tutorials on this. You could also search <fstream> on the web.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    "Piping" usually refers to sending data from one process to another so that the standard output of one process (cout) is connected to the standard input (cin) of the other one. This connection is graphically visualised as a "pipe" between the two processes, hence the name. This isn't C++ specific; you can pipe data between programs written in any language. http://en.wikipedia.org/wiki/Pipeline_%28Unix%29

    For example, to pipe the contents of 'file.txt' to program 'program' you could give the command "type file.txt | program" ('type' is the command in DOS to type out a file) If 'program' is written in C++ it would be able to read file.txt from "cin".

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    stdin and stdout are the terms you should be using there. Those are what would refer to your standard input and output in any language and system. I mention this because you could never read file.txt from "cin" (unless some wise ass wanted to cin a string that says "file.txt"). You're also being slightly close minded about the idea of piping. Yes, there are standard methods of piping in commands windows and certain programming languages (usually using the pipe '|' character), but if a person were to write a program that took a file and replaced all spaces in it with commas, that could be viewed as a pipe, as well. It takes input, passes it through a function or process, and outputs the result.
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    I mention this because you could never read file.txt from "cin"
    You don't consider the example that I gave as "reading file.txt from cin" ?

    I admit it's not really reading the file but rather the content of the file as it is being read and written out by another program. I would consider that as more or less the same thing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cont of IPC using PIPE
    By BMathis in forum C Programming
    Replies: 1
    Last Post: 03-15-2009, 05:16 PM
  2. Pipe class.
    By eXeCuTeR in forum Linux Programming
    Replies: 8
    Last Post: 08-21-2008, 03:44 AM
  3. Named pipe problem
    By rahul_c in forum C Programming
    Replies: 3
    Last Post: 10-02-2007, 05:40 PM
  4. Pipe(): Interprocess or Intraprocess comm?
    By @nthony in forum C Programming
    Replies: 2
    Last Post: 03-28-2007, 07:27 PM
  5. Having trouble with a named pipe
    By crazeinc in forum C Programming
    Replies: 2
    Last Post: 05-13-2005, 01:00 AM