Page 1 of 2
#STDIN to read input from console
Posted: Mon Dec 27, 2021 12:14 pm
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?

Re: #STDIN to read input from console
Posted: Mon Dec 27, 2021 12:49 pm
by airsoftsoftwair
Works here. Are you sure you're using Hollywood_Console.exe?
Re: #STDIN to read input from console
Posted: Mon Dec 27, 2021 4:06 pm
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

Re: #STDIN to read input from console
Posted: Mon Dec 27, 2021 9:54 pm
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

Re: #STDIN to read input from console
Posted: Tue Dec 28, 2021 3:51 pm
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.

Re: #STDIN to read input from console
Posted: Tue Dec 28, 2021 8:09 pm
by plouf
complete Out Of Topic, but whats the reason using a text based output ,and not GUI based one ?
Re: #STDIN to read input from console
Posted: Tue Dec 28, 2021 9:11 pm
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
Re: #STDIN to read input from console
Posted: Thu Dec 30, 2021 12:14 pm
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...
Re: #STDIN to read input from console
Posted: Thu Jan 06, 2022 12:17 pm
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?
Re: #STDIN to read input from console
Posted: Thu Jan 06, 2022 9:37 pm
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