open stdin a second time

Discussion in 'C Programming' started by fbertasso, Jun 9, 2008.

  1. fbertasso

    fbertasso Guest

    Hi,

    I´m opening stdin to get a file and pass it through a pipe.

    razor=popen ("/var/qmail/bin/razor-check -home=/var/qmail/razor",
    "w");
    while( (ret=fread(linha,1,sizeof(linha),stdin) ) > 0 ) {
    fwrite(linha,1,sizeof(linha),razor);
    }
    pclose(razor)

    After that, if razor returns me an error I want to send an email with
    the original message attached...but how can I re-read stdin to do
    that.

    I do not want to save the message to a temp file or save it to memory
    for i/o questions. Is there a way to re-read stdin ?

    Fernando
     
    fbertasso, Jun 9, 2008
    #1
    1. Advertising

  2. fbertasso

    rahul Guest

    On Jun 9, 6:46 pm, fbertasso <> wrote:
    > Hi,
    >
    > I´m opening stdin to get a file and pass it through a pipe.
    >
    > razor=popen ("/var/qmail/bin/razor-check -home=/var/qmail/razor",
    > "w");
    > while( (ret=fread(linha,1,sizeof(linha),stdin) ) > 0 ) {
    > fwrite(linha,1,sizeof(linha),razor);}
    >
    > pclose(razor)
    >
    > After that, if razor returns me an error I want to send an email with
    > the original message attached...but how can I re-read stdin to do
    > that.
    >
    > I do not want to save the message to a temp file or save it to memory
    > for i/o questions. Is there a way to re-read stdin ?
    >
    > Fernando


    Of course fgetpos and fsetpos or other seeking techniques are not
    going to work
    if you are taking the input from the keyboard. If you are reading from
    a file
    then ftell/fseek or fgetpos/fsetpos are at you disposable.

    To everyone else:
    Apart from disk files, is there any other stream which can be
    repositioned ( in the
    sense of seeking)?
     
    rahul, Jun 10, 2008
    #2
    1. Advertising

  3. fbertasso

    Chris Dollin Guest

    rahul wrote:

    > To everyone else:
    > Apart from disk files, is there any other stream which can be
    > repositioned ( in the
    > sense of seeking)?


    DECtape springs immediately to mind. This new-fangled flash memory
    which pretends to be a disk hobbles along soon afterward.

    Are there reversible paper tape readers?

    (Fondly remembering `revInFromFile` ...)

    --
    "I am afraid that this theory is quite untenable." /The Caves of Steel/

    Hewlett-Packard Limited registered office: Cain Road, Bracknell,
    registered no: 690597 England Berks RG12 1HN
     
    Chris Dollin, Jun 10, 2008
    #3
  4. In article <>,
    rahul <> wrote:

    >Apart from disk files, is there any other stream which can be
    >repositioned ( in the
    >sense of seeking)?


    Paper tape, some card readers, drum memory (provided it's refreshed),
    magnetic tape in its many varieties, optical tape, CDs and DVDs, flash
    memory, RAM "disks".

    -- Richard


    --
    In the selection of the two characters immediately succeeding the numeral 9,
    consideration shall be given to their replacement by the graphics 10 and 11 to
    facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
     
    Richard Tobin, Jun 10, 2008
    #4
  5. fbertasso

    Chris Dollin Guest

    Richard Tobin wrote:

    > In article <>,
    > rahul <> wrote:
    >
    >>Apart from disk files, is there any other stream which can be
    >>repositioned ( in the
    >>sense of seeking)?

    >
    > Paper tape, some card readers, drum memory (provided it's refreshed),
    > magnetic tape in its many varieties, optical tape,


    (fx:linebreak)

    > CDs and DVDs,


    Apart from silly marketing tricks, all the CDs and DVDs I've seen
    are disks ...

    (fx:linebreak)

    > flash memory, RAM "disks".



    --
    "I don't make decisions. I'm a bird." /A Fine and Private Place/

    Hewlett-Packard Limited Cain Road, Bracknell, registered no:
    registered office: Berks RG12 1HN 690597 England
     
    Chris Dollin, Jun 10, 2008
    #5
  6. In article <g2lh7g$oj2$>,
    Chris Dollin <> wrote:
    >>>Apart from disk files, is there any other stream which can be
    >>>repositioned ( in the
    >>>sense of seeking)?


    >> CDs and DVDs,

    >
    >Apart from silly marketing tricks, all the CDs and DVDs I've seen
    >are disks ...


    I was thinking of their use as linear storage (dump 0f /dev/acd0 /home),
    which makes them "disks" but not "disk files". Of course, by that
    reasoning I could have included magnetic disks of all kinds.

    -- Richard
    --
    In the selection of the two characters immediately succeeding the numeral 9,
    consideration shall be given to their replacement by the graphics 10 and 11 to
    facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
     
    Richard Tobin, Jun 10, 2008
    #6
  7. On 10 Jun 2008 at 4:43, rahul wrote:
    > To everyone else: Apart from disk files, is there any other stream
    > which can be repositioned ( in the sense of seeking)?


    Maybe it would be quicker to list the streams that can't be
    repositioned... tty, pipes, sockets - any others?
     
    Antoninus Twink, Jun 10, 2008
    #7
  8. In article <>,
    Antoninus Twink <> wrote:

    >Maybe it would be quicker to list the streams that can't be
    >repositioned... tty, pipes, sockets - any others?


    Many physical devices - TV tuners, modems, random number generators...

    -- Richard



    --
    In the selection of the two characters immediately succeeding the numeral 9,
    consideration shall be given to their replacement by the graphics 10 and 11 to
    facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
     
    Richard Tobin, Jun 10, 2008
    #8
  9. In article <g2lb50$ftn$>,
    Chris Dollin <> wrote:

    >Are there reversible paper tape readers?


    http://www.freepatentsonline.com/3014092.html
    United States Patent 3014092 "High speed reversible tape reader"
    (December 19, 1961)
    --
    "And believe me, I was very lousy yesterday.
    I had nothing to say, and, by God, I said it."
    -- Walter Wellesley Smith
     
    Walter Roberson, Jun 10, 2008
    #9
  10. On Tue, 10 Jun 2008 10:10:13 UTC, Antoninus Twink
    <> wrote:

    > On 10 Jun 2008 at 4:43, rahul wrote:
    > > To everyone else: Apart from disk files, is there any other stream
    > > which can be repositioned ( in the sense of seeking)?

    >
    > Maybe it would be quicker to list the streams that can't be
    > repositioned... tty, pipes, sockets - any others?
    >

    punch cards, magnetic cards, paper types

    There are even devices who are write only:

    printers, card writer, plotters, graphic tablets

    Some of the above are limited in the ability to be repositioned, some
    not, some totally unable depending on the specific type.

    There are devices you can read multiple times like disk but write only
    once depending on the media inserted:

    CD ROM, DVD ROM, EPROM


    --
    Tschau/Bye
    Herbert

    Visit http://www.ecomstation.de the home of german eComStation
    eComStation 1.2R Deutsch ist da!
     
    Herbert Rosenau, Jun 15, 2008
    #10
  11. On 10 Jun 2008 08:54:44 GMT, (Richard Tobin)
    wrote:

    > In article <>,
    > rahul <> wrote:
    >
    > >Apart from disk files, is there any other stream which can be
    > >repositioned ( in the
    > >sense of seeking)?

    >
    > Paper tape, some card readers, drum memory (provided it's refreshed),


    I assume this means classic punched or optical-mark; not newer
    (plastic) cards like mag-stripe and RFID, mostly for ID, access and
    payment rather than data as such. I knew of some readers that could
    'catch' a card in the path after reading e.g. for an alternate stacker
    but none that could actually go backward. (Or skip forward either.)

    > magnetic tape in its many varieties, optical tape,


    But usually not to arbitrary bytes, thus fitting the fget,setpos model
    rather than the fseek (tell/seek) model. Except as noted DECtape.

    > CDs and DVDs, flash > memory, RAM "disks".


    - formerly david.thompson1 || achar(64) || worldnet.att.net
     
    David Thompson, Jun 24, 2008
    #11
  12. In article <>,
    David Thompson <> wrote:

    >> >Apart from disk files, is there any other stream which can be
    >> >repositioned ( in the sense of seeking)?


    >> Paper tape, some card readers, drum memory (provided it's refreshed),


    >I assume this means classic punched or optical-mark; not newer
    >(plastic) cards like mag-stripe and RFID, mostly for ID, access and
    >payment rather than data as such. I knew of some readers that could
    >'catch' a card in the path after reading e.g. for an alternate stacker
    >but none that could actually go backward. (Or skip forward either.)


    I was thinking of ones that could re-read the whole deck. You don't
    have to go backwards to seek.

    >> magnetic tape in its many varieties, optical tape,

    >
    >But usually not to arbitrary bytes, thus fitting the fget,setpos model


    That's equally true of magnetic disks! The byte-level seeking can be
    simulated in software, while the hardware deals in blocks.

    -- Richard
    --
    In the selection of the two characters immediately succeeding the numeral 9,
    consideration shall be given to their replacement by the graphics 10 and 11 to
    facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
     
    Richard Tobin, Jun 24, 2008
    #12
  13. In article <>,
    David Thompson <> wrote:
    >On 10 Jun 2008 08:54:44 GMT, (Richard Tobin)
    >wrote:


    >> Paper tape, some card readers, drum memory (provided it's refreshed),


    >I assume this means classic punched or optical-mark; not newer
    >(plastic) cards like mag-stripe and RFID, mostly for ID, access and
    >payment rather than data as such. I knew of some readers that could
    >'catch' a card in the path after reading e.g. for an alternate stacker
    >but none that could actually go backward. (Or skip forward either.)


    A "tub file" perhaps??
    http://en.wikipedia.org/wiki/Tub_file
    --
    "Whenever there is a hard job to be done I assign it to a lazy
    man; he is sure to find an easy way of doing it."
    -- Walter Chrysler
     
    Walter Roberson, Jun 24, 2008
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johnathan Doe

    peek at stdin, flush stdin

    Johnathan Doe, May 15, 2004, in forum: C Programming
    Replies:
    5
    Views:
    25,463
    Chatoyer
    May 17, 2013
  2. Charlie Zender

    Reading stdin once confuses second stdin read

    Charlie Zender, Jun 19, 2004, in forum: C Programming
    Replies:
    6
    Views:
    824
    Dan Pop
    Jun 21, 2004
  3. Ben
    Replies:
    2
    Views:
    1,409
    jacob navia
    Aug 29, 2009
  4. amit khan

    open stdin a second time

    amit khan, May 25, 2010, in forum: C Programming
    Replies:
    3
    Views:
    1,387
    Seebs
    May 25, 2010
  5. FBert

    open stdin a second time

    FBert, Nov 11, 2011, in forum: C Programming
    Replies:
    2
    Views:
    383
    Eric Sosman
    Nov 12, 2011
Loading...

Share This Page