Announcement

Collapse
No announcement yet.

Trying to get input from STDIN

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

  • David J Venable
    replied
    Here's a short one that everyone seems to forget about:

    open "kybd:" for input as #1
    x$=input$(1, 1)
    print x$

    Using the open statement, kybd: is stdin, and cons: is
    stdout.

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

    Leave a comment:


  • Lance Edmonds
    replied
    Originally posted by Crey Stone:
    And its very cheap too
    Good luck! Just remember that you get what you pay for.




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

    Leave a comment:


  • Scott Slater
    replied
    Originally posted by Crey Stone:
    To Scott:
    Yes i know but i was too lazy to write all that code because i was working with eval version.. "Cant load ;-("
    Did you try cut n' paste through windows (if you are running under windows).



    ------------------
    Scott Slater
    Summit Computer Networks
    www.summitcn.com

    Leave a comment:


  • Crey Stone
    Guest replied
    To Michael: It did not get input from STDIN

    To Scott:
    Yes i know but i was too lazy to write all that code because i was working with eval version.. "Cant load ;-("
    And after some surfing i found IBasic http://www.pyxia.com/ it can do 32bit console that i needed.

    And its very cheap too only $34.95

    Thanks
    Crey

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

    Leave a comment:


  • Scott Slater
    replied
    Originally posted by Crey Stone:
    Hmm.. so i need full version of PB 3.2 or 3.5 to try it?
    .. or is there eval 3.5 somewhere?

    Thanks
    Crey

    Hi Crey, you can use the code Lance posted above like:

    Code:
    '===========================================================================
    ' StdIn - Read a char from STDIN and return it as a string.
    '
    ' Note:  Great for reading information which is redirected from a file.
    '
    FUNCTION STDIN() PUBLIC AS STRING
     
      DIM eFlag AS BYTE
      DIM nKey  AS BYTE
     
      ! push    DS                      ; save DS for PowerBASIC
     
      ! mov     AH, &H0B                ; DOS function 0Bh, check STDIN
      ! int     &H21                    ; call DOS
      ! cmp     AL, &HFF                ; FFh if char is available
      ! jne     Done                    ; no, we're done
     
      ! mov     AH, &H07                ; DOS function 07h, get char from STDIN
      ! int     &H21                    ; call DOS
      ! mov     nKey, AL                ; put value in nKey
      ! or      AL, AL                  ; was char a zero?  (extended key)
      ! jnz     Done                    ; no, exit
     
      ! mov     eFlag, 1                ; set extended key flag
      ! mov     AH, &H07                ; DOS function 07h, get char from STDIN
      ! int     &H21                    ; call DOS
      ! mov     nKey, AL                ; put value in nKey
    Done:
      ! pop     DS                      ; restore DS for PowerBASIC
     
      IF eFlag THEN
        FUNCTION = CHR$(0, nKey)        ' return extended key
      ELSEIF nKey THEN
        FUNCTION = CHR$(nKey)           ' return regular key
      END IF
     
    END FUNCTION
    
    DO UNTIL s$ = ""
      s$ = STDIN   ' Call Lances Function Above...
      l$ = l$ + s$
    LOOP
    PRINT l$


    ------------------
    Scott Slater
    Summit Computer Networks
    www.summitcn.com

    Leave a comment:


  • Michael Mattias
    replied
    can do this with MS Quick basic like
    Code:
    DO UNTIL s$ = " "
      s$ = INPUT$(1)
      l$ = l$ + s$
    LOOP
    PRINT l$
    But not with PB.. anyone know whats wrong
    What's the problem? Won't compile? Run-time error? Results not as predicted?

    FWIW, there is no reason to use redirection here. Just get the file name from COMMAND$, OPEN the file in your program and read it that way.

    MCM

    Leave a comment:


  • Crey Stone
    Guest replied
    Hmm.. so i need full version of PB 3.2 or 3.5 to try it?
    .. or is there eval 3.5 somewhere?

    Thanks
    Crey

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

    Leave a comment:


  • Lance Edmonds
    replied
    (This reply intended to generate a new reply-notification to Crey so he can find where the topic was moved to).

    Leave a comment:


  • Lance Edmonds
    replied
    Hi Crey, welcome to the PowerBASIC Peer Support Forums.

    Please note that you posted your question to the PB/CC (Console Compiler for Windows) forum, so I've moved the topic here to the PB/DOS forum.

    The problem you face is that the STDIN statement used in the examples you previewed was not built-in to PB/DOS 3.2, but is available in the current version (PB/DOS 3.5).

    However, the full version of PB/DOS 3.2 did come with a set of routines that provided STDIN functionality (as well as STDOUT, STDERR, etc), but since PB/DOS 3.5 directly supports STDIN and related functions, the discrete code is redundant as far as the current version is concerned.

    That said, the following is the code for the STDIN function, as it was supplied with PB/DOS 3.2...
    Code:
    '===========================================================================
    ' StdIn - Read a char from STDIN and return it as a string.
    '
    ' Note:  Great for reading information which is redirected from a file.
    '
    FUNCTION STDIN() PUBLIC AS STRING
     
      DIM eFlag AS BYTE
      DIM nKey  AS BYTE
     
      ! push    DS                      ; save DS for PowerBASIC
     
      ! mov     AH, &H0B                ; DOS function 0Bh, check STDIN
      ! int     &H21                    ; call DOS
      ! cmp     AL, &HFF                ; FFh if char is available
      ! jne     Done                    ; no, we're done
     
      ! mov     AH, &H07                ; DOS function 07h, get char from STDIN
      ! int     &H21                    ; call DOS
      ! mov     nKey, AL                ; put value in nKey
      ! or      AL, AL                  ; was char a zero?  (extended key)
      ! jnz     Done                    ; no, exit
     
      ! mov     eFlag, 1                ; set extended key flag
      ! mov     AH, &H07                ; DOS function 07h, get char from STDIN
      ! int     &H21                    ; call DOS
      ! mov     nKey, AL                ; put value in nKey
    Done:
      ! pop     DS                      ; restore DS for PowerBASIC
     
      IF eFlag THEN
        FUNCTION = CHR$(0, nKey)        ' return extended key
      ELSEIF nKey THEN
        FUNCTION = CHR$(nKey)           ' return regular key
      END IF
     
    END FUNCTION
    I hope this helps!


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

    Leave a comment:


  • Crey Stone
    Guest started a topic Trying to get input from STDIN

    Trying to get input from STDIN

    Hello!

    Iam trying to make simple program that reads input from another file
    like myprog.exe <myfile.txt

    I can do this with MS Quick basic like

    DO UNTIL s$ = " "
    s$ = INPUT$(1)
    l$ = l$ + s$
    LOOP
    PRINT l$

    But not with PB.. anyone know whats wrong?
    Iam using PB Evaluation version 3.20 first day
    I have read some examples and they use STDIN but i cant use it??

    Thanks
    Crey
Working...
X