How do I capture <STDIN>?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
mikegoyette
Newbie
Posts: 1
Joined: Fri Feb 06, 2009 1:05 pm

How do I capture <STDIN>?

Post 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???
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post 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
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Post Reply