#STDIN to read input from console

Discuss any general programming issues here
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

#STDIN to read input from console

Post by Allanon »

Hello,
maybe I'm doing something wrong but I'm not able to read input from the console (on Windows) opening #STDIN file, here is my snippet I used for the test:

CODE

Code: Select all

  Local fid = OpenFile(Nil, #STDIN, #MODE_READ)
  While True
    ExitOnError(False)
    Local c = ReadChr(fid)
    Local le = GetLastError()   
    ExitOnError(True)
    If le <> 0 Then DebugPrint("ERROR: ", le, GetErrorName(le))
    If Not(IsNil(c))
      DebugPrint("-> ", c)
    EndIf
  Wend
OUTPUT

Code: Select all

ERROR:  1009 Could not read all characters from file!
Check if it is read protected!
I'm running it from the interpreter, any hints? :)
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: #STDIN to read input from console

Post by airsoftsoftwair »

Works here. Are you sure you're using Hollywood_Console.exe?
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: #STDIN to read input from console

Post by Allanon »

Hi and Thanks!
You are right, I was not using the hollywood_console executable but there is still a problem: the input is read only after I hit the enter key, is this the standard behaviour?
I've tried to search for hollywood_console.exe in the guide but I was not able to find any references to it, is it there :)
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: #STDIN to read input from console

Post by airsoftsoftwair »

Allanon wrote: Mon Dec 27, 2021 4:06 pm Hi and Thanks!
You are right, I was not using the hollywood_console executable but there is still a problem: the input is read only after I hit the enter key, is this the standard behaviour?
Yes. The console is line buffered and that buffer won't be flushed before you hit enter so that's the normal behaviour.
Allanon wrote: Mon Dec 27, 2021 4:06 pm I've tried to search for hollywood_console.exe in the guide but I was not able to find any references to it, is it there :)
No, it isn't. I didn't want to confuse the user because Windows apps have these strange distinction between Windows and console mode which can be rather confusing. But Hollywood_Console.exe has been there for a long time. Maybe I should really mention it ;)
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: #STDIN to read input from console

Post by Allanon »

ah, ok! Thank you! :)

btw, are there any chances to stream input from the console without hitting the enter key? Or maybe a DebugPrompt() version which get a single keystroke as input?

The problem I have is that I've built some applications that run in the console and hitting the enter key for some input type isn't very handy.
For example I've coded a listview control for the console and the user should be able to move througth the data simply hitting a single key, right now, for each entry, he has to hit that key followed by the enter key.

Image
plouf
Posts: 467
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: #STDIN to read input from console

Post by plouf »

complete Out Of Topic, but whats the reason using a text based output ,and not GUI based one ?
Christos
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: #STDIN to read input from console

Post by Allanon »

@plouf

Hi plouf, it's a legit question! :)

I need to run some applications on linux servers without gui but straight from the console
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: #STDIN to read input from console

Post by airsoftsoftwair »

Allanon wrote: Tue Dec 28, 2021 3:51 pm btw, are there any chances to stream input from the console without hitting the enter key? Or maybe a DebugPrompt() version which get a single keystroke as input?
Could probably be easily added for Windows and Linux but on AmigaOS it's more difficult...
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: #STDIN to read input from console

Post by amyren »

Judging from the discussion in this thread you can not use commands like IsKeyDown to capture input, or use OnRawkeyDown events. Or is it me misunderstanding the issue here?
I never tried creating any console applications with Hollywood, so I am not sure how it works.
Obviously the main difference is no normal GUI, but what other features can not be used?
Are there any examples available for console only prorgrams?
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: #STDIN to read input from console

Post by Allanon »

Hi @amyren,
you are right, keypresses cannot be detected because, IIRC, these events are attached to windows while console programs does not have windows, so the only method is to use the DebugPrompt command or opening a file on #STDIN, but having to press enter to finalize the input it is almost like using DebugPrompt.

Right now I don't have access to my files but if you are interested I have coded a library to help with ansi codes & terminal apps which includes some test code:
https://github.com/Allanon71/Hollywood-MAL-Libraries
Post Reply