Announcement

Collapse
No announcement yet.

problems redirecting with kybd:

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • problems redirecting with kybd:

    I'm trying to make one of my programs read a file from
    standard input, but I have had some trouble. (using pb 3.1)
    If I use EOF() I get error 54 (bad file mode), and if I
    look for ascii 26 it just keeps looping

    example:

    open "kybd:" for input as #1
    open "file.x" for output as #2
    while 1
    x$=input$(1, 1)
    if x$=chr$(26) then exit loop
    print #2, x$;
    wend


    The program writes all of the input into "file.x", but
    it never finds the eof. Any help that anyone can offer
    will be of great assistance.

    Dave

    ------------------

  • #2
    I don't understand why you need to open the keyboard for input.
    Try this:

    open "file.x" for binary as #1

    do
    if instat<>0 then
    an$ = inkey$
    if an$ = chr$(26) then exit loop
    put$ #1,an$
    end if
    loop


    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      Mel, David says he wants to read from Standard Input, which is not necessarily originating from the keyboard - it could be a redirection from another program or a file.

      David, have you tried using the STDIN statement? It was implemented in PB/DOS 3.5 and it should provide the functionality your require.


      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        No I haven't--I'm still using 3.1. Is there any
        way to detect an eof when using kybd:? Does kybd:
        return every character except for 26? I'm not sure
        why this wouldn't work, unless it's some sort of
        internal thing.

        ------------------

        Comment


        • #5
          Have you tried the STDIN and related functions in DOSUNIT.BAS in the PB3.1 example folder?

          Anyway, the following is a "simple" way to do it, simply by terminating the loop under error conditions (such as input past end after a CTRL+Z).
          Code:
          cls
          on error resume next
          open "kybd:" for input as #1
          a$ = ""
          do
            a$ = input$(1,1)
            if err then exit loop
            print a$, ascii(a$)
          loop
          close #1
          print
          print "Redirection done!"
          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:lancee[email protected]

          Comment

          Working...
          X