Page 1 of 1

How do I capture <STDIN>?

Posted: Fri Feb 06, 2009 1:14 pm
by mikegoyette
OK, I wrote this program called Crypto that runs other programs in the background and captures their output and displays it in a window in HTML.

It also captures input from the window and send it to the other programs standard input.

OK, for QBasic and QB4.5, the output works perfectly, but the input part hangs.

Here's what I mean:

PRINT "<center><h1>Hello, World!</h1></center>"
SYSTEM

works just fine.

But

INPUT "", a$
PRINT a$
SYSTEM

hangs, instead of echoing the input back to the window.

I think this is because INPUT doesn't read from STDIN but instead is using a keyboard interrupt to read the keyboard directly. So I need to open STDIN as a file???

How do I do that???

Posted: Sun Feb 15, 2009 3:40 pm
by Ralph
Right! To read from a file, one must tell QB to first open it. Assuming your file, STDIN, has no extension and is in the same directory as qb.exe, here's how:

Code: Select all

OPEN "STDIN" FOR INPUR AS #1 
  WHILE NOT EOF(1)  'allows reading all the lines in the opened file
     LINE INPUT #1, A$   'assigns the first line to the string variable A$ 
     'your code here, to use the current data in A$
   WEND
CLOSE #1