How to pipe an image into another program's stdin?

This is a discussion on How to pipe an image into another program's stdin? within the C Programming forums, part of the General Programming Boards category; So, there's this program called gocr that reads numbers and letters and it works great! But what I need it ...

  1. #1
    Registered User 3Nex's Avatar
    Join Date
    May 2010
    Location
    Croatia
    Posts
    13

    How to pipe an image into another program's stdin?

    So, there's this program called gocr that reads numbers and letters and it works great! But what I need it to do, is read a portion of an image, so I made my own program that extracts that portion and makes a new "image" (in the memory) out of it. Now, gocr can take an image from stdin instead of from a file (it says so in the man page), and I would like to use that option because it seems it would be a lot faster. But I don't know how to do this..

    So what I need is to execute gocr from my program, pass a image from my struct to his stdin and set his argument to let him know to read it from the stdin (from terminal that argument would be gocr -i -), then read his stdout back into my program.

    Oh, and... it's all running on Ubuntu, I dunno if that makes a difference..

    How would I do that?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The magic word is indeed pipe. Have you typed "man pipe" at your terminal to read the manual? (The example is a one-way pipe; since you appear to need both directions, you'll have to open two pipes.)

    EDIT: And I suppose I should add "exec" to the things you'll want to read up on.
    Last edited by tabstop; 05-22-2010 at 02:44 PM.

  3. #3
    Registered User 3Nex's Avatar
    Join Date
    May 2010
    Location
    Croatia
    Posts
    13
    Quote Originally Posted by tabstop View Post
    ...
    Oh there's a function called pipe.. How appropriate Thank you.

    And there is one more thing I have to do. How can I pass arguments to gocr from my program? As noted in my previous post, I need to send the -i argument (to let him know the image is coming up) and then a dash (because if the argument after -i was anything but a dash, it would be an image file name).

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    It's not really a function it's done by the | character at the command line, in your example I imagine you would do something like this:

    Code:
    ./yourprogram ~/path/to/file | gocr -i -

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by 3Nex View Post
    Oh there's a function called pipe.. How appropriate Thank you.

    And there is one more thing I have to do. How can I pass arguments to gocr from my program? As noted in my previous post, I need to send the -i argument (to let him know the image is coming up) and then a dash (because if the argument after -i was anything but a dash, it would be an image file name).
    So did you read "man exec" like you were supposed to?

  6. #6
    Registered User 3Nex's Avatar
    Join Date
    May 2010
    Location
    Croatia
    Posts
    13
    Quote Originally Posted by tabstop View Post
    So did you read "man exec" like you were supposed to?
    Oh.. No, sorry.. Thx.. again.. I guess.. Reading up on stuff always gets me so confused that I forget other stuff I have to read.. Sometimes I google so much I forget what I was looking for..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. image analysis theory: mapping a network
    By elninio in forum C++ Programming
    Replies: 5
    Last Post: 10-30-2008, 01:23 PM
  2. HotSpot image controls (web)
    By novacain in forum C# Programming
    Replies: 0
    Last Post: 06-25-2008, 04:27 AM
  3. Loading an image in from a resource file
    By starcatcher in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 06:44 AM
  4. making a proper image for floppy
    By EvBladeRunnervE in forum Tech Board
    Replies: 4
    Last Post: 07-31-2004, 11:27 PM
  5. Pipe the console from a DLL
    By loobian in forum Windows Programming
    Replies: 12
    Last Post: 11-30-2003, 07:55 PM

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