1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Documentation @LINE[CON,n] @LINES[CON] not documented (bug?)

Discussion in 'Support' started by tmpease, Nov 27, 2012.

  1. tmpease

    Joined:
    Jan 22, 2009
    Messages:
    10
    Likes Received:
    0
    The only help-file example of using @LINE on redirected standard input is
    (echo %@line[con,0]) < myfile.dat​
    which does work.

    However, the assumption is that, if myfile.dat is, forexample:
    a​
    b​
    c​
    , then
    (echo 0=%@line[con,0] 1=%@line[con,1] 2=%@line[con,2]) < myfile.dat​
    "should" echo
    0=a 1=b 2=c​
    . Instead it echos (bug??)
    0=a 1=c 2=**EOF**​
    . It should be documented that the way to make this example work is:
    (echo 0=%@line[con,0] 1=%@line[con,0] 2=%@line[con,0]) < myfile.dat ​
    0=a 1=b 2=c​

    . Apparently STDIN cannot be "rewound" after being accessed. This means that @LINES[CON] can never be used because it "consumes" all of STDIN.

    Therefore, here's an example to process STDIN in a batch file:
    set i=-1
    do until "%[linecon%i]" == "**EOF**"​
    set i=%@INC[%i]
    set linecon%i=%@LINE[CON,0]
    enddo
    set linecon%i=
    set linescon=%@DEC[%i]​
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,855
    Likes Received:
    83
    WAD -- Windows (unlike Linux) doesn't let you rewind character devices.
     
  3. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    Can one use @FILEREAD to read stdin? The issue is how to get stdin's file descriptor - using the 'intuitive' (for linux) 0 doesn't work.

    OT, I remember having seen a 4NT [sic] plugin that provides a specialized console read function, but I can't trace that plugin anymore. Does anyone know?
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,855
    Likes Received:
    83
    Yes - use "@FILEOPEN[con:,r]" first to get the handle.
     
  5. tmpease

    Joined:
    Jan 22, 2009
    Messages:
    10
    Likes Received:
    0
    I think the documentation for @LINE , @LINES , and @FILEOPEN should be updated based on this thread.
     

Share This Page