Help understanding complaint

Here you can talk about anything related to BBC BASIC, not covered in another category
Hated Moron

Help understanding complaint

Post by Hated Moron »

I have received several emails from somebody complaining about my BBC BASIC Console Mode versions (specifically the Windows edition I think). The gist of the complaint seems to be this:
I have tested it, but it does not output the PRINT information to STDOUT
He additionally says that he has tried:
about 50 arbitrary other console application computer languages
which work correctly, but that BBC BASIC does not. In order to fix it he recommends:
On Microsoft Windows, these functions can be used in a console command line executable to implement STDOUT and STDERR:
The standard library class std::cout can be used to print text to STDOUT
and the standard library class std::cerr can be used to print text to STDERR.
I am finding this difficult to understand. If BBC BASIC isn't currently sending its console output to STDOUT where is it going? I know that Windows is probably rather different from Linux in this regard, but I thought the same code could be used. And why do I need to incorporate what seems to me to be C++ code in an existing C application? Surely it must be possible to output to STDOUT in C?

I have sent a 'holding' reply basically saying the above, but he is very persistent (not to say annoying)! Can somebody more knowledgeable than me (not difficult) advise on what the problem may be and how it can be fixed, preferably without C++ code?
User avatar
JeremyNicoll
Posts: 72
Joined: Sun 26 Jul 2020, 22:22
Location: Edinburgh

Re: Help understanding complaint

Post by JeremyNicoll »

I use any number of command-line utilities (which are .exe's) and run them from a cmd.exe terminal window.

When I do that, their stdout and (if they create any) stderr are written to the terminal window, and can be redirected with the usual > and >> and &1 and &2 symbology.

So what happens if someone runs your console mode interpreter starting it from within a command window?
Hated Moron

Re: Help understanding complaint

Post by Hated Moron »

On 19/03/2023 12:45, R NBW wrote (cross-posted from the Discussion Group:
I have used C and C++ only very rarely and very much at beginner stage. However, I Googled “stdout in C using Windows” and found this response in stackoverflow:

(Huge amount of stuff deleted)

Does any of this make sense and help you?
None whatever, sorry. You've done very much what the complainant did: state that BBC BASIC doesn't do it correctly (at least, I assume you are agreeing with him in that regard) but not giving a clue as to what I should do about it - using language that I can understand anyway.

Perhaps you would take a look at the existing code, tell me what you find wrong with it and (ideally) suggest some changes that can be made. The key section of code, i.e. the part which is supposed to output to STDOUT in Windows, is this in bbccos.c:

Code: Select all

	fwrite (&vdu, 1, 1, stdout) ;
You will note that (1) this code is used in both Linux and Windows and (2) it explicitly references 'stdout' (but I'm not sure where that is declared).
Hated Moron

Re: Help understanding complaint

Post by Hated Moron »

JeremyNicoll wrote: Sun 19 Mar 2023, 13:15 So what happens if someone runs your console mode interpreter starting it from within a command window?
Can't you try it yourself? If not, why not? Far better that somebody who understands what should happen tries it than somebody who doesn't!

If there's something about the existing Console Mode edition of BBC BASIC which makes it difficult for you to run it, that in itself should probably be a cause for concern.

It is beginning to look likely that in the couple of years since I released the Console Mode interpreters only one person has ever attempted to run the Windows build, and that is the person who has been complaining by email.

With such a low take-up, would the simplest answer be to withdraw the Windows build altogether?
Hated Moron

Re: Help understanding complaint

Post by Hated Moron »

On 19/03/2023 14:19, Daniel Bingamon wrote (cross-posted from the Discussion Group):
I think the problem is that he does realized that the product BBC4W is for Windows. It's not BBC4D (for DOS). Stdin, Stdout, Stderr is a DOS thing.
He's definitely not using BBC BASIC for Windows (or indeed BBC BASIC for SDL 2.0) by mistake. He's certainly running the Console Mode edition because he explicitly lists the executable name as follows:

Code: Select all

> bbcbasic.exe
BBC BASIC for Win64 Console v0.42
(C) Copyright R. T. Russell, 2023
>*quit
You will note that the executable is bbcbasic.exe whereas BB4W is bbcwrun6.exe and BBCSDL is bbcsdl.exe. Additionally it is announcing itself as BBC BASIC for Win64 Console v0.42.

So your theory, whilst it would indeed explain his observations, is not correct. Let's not muddy the waters by bringing BB4W or BBCSDL into this.
User avatar
JeremyNicoll
Posts: 72
Joined: Sun 26 Jul 2020, 22:22
Location: Edinburgh

Re: Help understanding complaint

Post by JeremyNicoll »

C:\>"C:\Users\--myuserid--\Downloads\bbcbasic_console_win64\bbcbasic.exe" "sortdemo.bbc"
?[6n?[6nB?[6nB?[6nC?[6n ?[6nB?[6nA?[6nS?[6nI?[6nC?[6n ?[6nf?[6no?[6nr?[6n ?[6nW?[6ni?[6nn?[6n6?[6n4?[6n ?[6nC?[6no?[6nn?[6ns?[6no?[6nl?[6ne?[6n ?[6nv?
?[6n?[6n.?[6n4?[6n2?[6n
?[6n?[6n(?[6nC?[6n)?[6n ?[6nC?[6no?[6np?[6ny?[6nr?[6ni?[6ng?[6nh?[6nt?[6n ?[6nR?[6n.?[6n ?[6nT?[6n.?[6n ?[6nR?[6nu?[6ns?[6ns?[6ne?[6nl?[6nl?[6n,?[6n ?
?[6n?[6n0?[6n2?[6n3?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n?[4i?[6n?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n
?[6n?[6n>?[6n?[6n
?[6n?[15;2H?[6n>?[6n
?[6n?[6n>

and I couldn't stop it with Ctrl-Z or Ctrl-G or Ctrl-C

terminated bbcbasic.exe via ProcessHacker


C:\>"C:\Users\--myuserid--\Downloads\bbcbasic_console_win64\bbcbasic.exe" "8queens.bbc"
?[6n?[6nB?[6nB?[6nC?[6n ?[6nB?[6nA?[6nS?[6nI?[6nC?[6n ?[6nf?[6no?[6nr?[6n ?[6nW?[6ni?[6nn?[6n6?[6n4?[6n ?[6nC?[6no?[6nn?[6ns?[6no?[6n
C:\>
C:\>

terminated via ProcessHacker


on the other hand, this worked

C:\>"C:\Users\--myuserid--\Downloads\bbcbasic_console_win64\bbcbasic.exe" -help
BBC BASIC for Win64 Console v0.42 (C) Copyright R. T. Russell, 2023

The command syntax is: bbcbasic [option] [bbcfile]

where <option> is one of:
-help Display this message.
-load Load BASIC program <bbcfile> but don't run it.
-quit Run BASIC program <bbcfile> and quit when it ends.
otherwise run <bbcfile> (if any) and stay in the interpreter.

C:\>


I wondered if it the weird stuff above had actually found the program, so tried:

C:\>"C:\Users\--myuserid--\Downloads\bbcbasic_console_win64\bbcbasic.exe" -quit nosuchfile.bbc
?[6n?[6nB?[6nB?[6nC?[6n ?[6nB?[6nA?[6nS?[6nI?[6nC?[6n ?[6nf?[6no?[6nr?[6n ?[6nW?[6ni?[6nn?[6n6?[6n4?[6n
C:\>

which casts doubt - and also tried a run with -quit - for a file that's meant to exist.

C:\>
C:\>"C:\Users\--myuserid--\Downloads\bbcbasic_console_win64\bbcbasic.exe" -quit 8queens.bbc
?[6n?[6nB?[6nB?[6nC?[6n ?[6nB?[6nA?[6nS?[6nI?[6n

Trying a command with an explicit path to the .bbc file didn't work either:

C:\>"C:\Users\--myuserid--\Downloads\bbcbasic_console_win64\bbcbasic.exe" -quit "C:\Users\--myuserid--\Downloads\bbcbasic_console_win64\8queens.bbc"
←[6n←[6n←[8;32;80t←(B←[37m←[40m←[H←[J←[6n←[?25l←[6n←[31;22H←[6nE←[6nI←[6nG←[6nH←[6nT←[6n ←[6nQ←[6nU←[6nE←[6nE←[6nN←[6nS←[6n ←[6nP←[6nU←[6nZ←[6nZ←[6n
C:\>


Clealry the mystery is why a -help call worked but none of the other do... unless the programs I picked to try require a better emulation of a console than cmd.exe gives.
Hated Moron

Re: Help understanding complaint

Post by Hated Moron »

On 19/03/2023 14:30, Ray Would via groups.io wrote (cross-posted from the Discussion Group):
You've misunderstood completely what I have done. I have not agreed with anyone.
Sorry if I misunderstood (comprehension is something that has suffered as a result of my cognitive decline) but I assumed that you wouldn't be listing a huge dollop of text from Stack Overflow if you believed that the existing code worked correctly and no changes were necessary! :roll:

Before this blew up I would have said I was 99.9% sure that the existing code was correct. All my tests suggest that BBC BASIC is outputting to STDOUT: the code is the same in Linux and in Windows, it looks right to me, and I can redirect the output to a file in Windows in exactly the way you would expect.

I hoped that by posting about it here I would receive several responses of the "it works perfectly for me, I think your correspondent is mistaken" kind, but I have been absolutely gobsmacked to receive nothing like that but rather only a confirmation that he is right. :shock:

So I am puzzled and confused (nothing new there, but this is the last thing I would have expected anybody to complain about). :?
Hated Moron

Re: Help understanding complaint

Post by Hated Moron »

On 19/03/2023 14:52, Sean Miller wrote (cross-posted from the Discussion Group):
Surely better to say what they're trying to do and the symptoms and then let you find the solution
To be fair, I only listed a small extract from his email, so there was context (I don't think it would have been helpful the list the whole thing, and there are privacy concerns in copying the contents of a private email into a public forum). Here is the specific code which he listed to 'demonstrate' that it is not outputting to STDOUT:

Code: Select all

Here my testing output:

1. FIRST CHECKING THE BBCBASIC CONSOLE VERSION, THAT IS INDEED v0.42
> bbcbasic.exe
BBC BASIC for Win64 Console v0.42
(C) Copyright R. T. Russell, 2023
>*quit

2. DELIBERATELY INTRODUCING ERRORS IN THE HELLOWORLD EXAMPLE PROGRAM
> type helloworld.bas
PRINT "Hello world"
PRINT a b c d
*QUIT

RUNNING THE COMMAND LINE WITHOUT -quit
> bbcbasic.exe helloworld.bas >ddd.txt 2>&1

CHECKING THE FILE SIZE OF DDD.TXT (=zero bytes)
> dir ddd.txt
19-03-2023  01:40               0  ddd.txt

RUNNING THE COMMAND LINE WITH -quit
> bbcbasic.exe -quit helloworld.bas >ddd.txt 2>&1

CHECKING THE FILE SIZE OF DDD.TXT (=zero bytes)
> dir ddd.txt
19-03-2023  01:42               0  ddd.txt
Note that he mistakenly tries to run a .bas program (plain-text format) rather than a .bbc program (tokenised format) which muddies the waters.
than start mentioning STDOUT etc. as if that is even a concept in Windows!!!
Of course STDOUT is a "concept in Windows", that is what this whole thing is about. My correspondent is claiming that the BBC BASIC Console Mode edition for Windows is not outputting to STDOUT when it should be! :?
User avatar
JeremyNicoll
Posts: 72
Joined: Sun 26 Jul 2020, 22:22
Location: Edinburgh

Re: Help understanding complaint

Post by JeremyNicoll »

https://ss64.com/nt/syntax-redirection.html

describes Windows' handles 0, 1 and 2 as stdin, stout, stderr and - at least in use from a cmd.exe terminal window I've never had a problem with teh corresponding redirections from/to files.

When using something like curl which offers explicit parms for specifying files from which to take input, and to write fetched data, page hearders, cookies to etc, I don't use redirection, but I think I'd expect it to work.

Or using Sysinternals' "handle.exe" ...

C:\>handle /?

Nthandle v4.22 - Handle viewer
Copyright (C) 1997-2019 Mark Russinovich
Sysinternals - www.sysinternals.com

usage: handle [[-a [-l]] [-u] | [-c <handle> [-y]] | [-s]] [-p <process>|<pid>] [name] [-nobanner]
-a Dump all handle information.
-l Just show pagefile-backed section handles.
-c Closes the specified handle (interpreted as a hexadecimal number).
You must specify the process by its PID.
WARNING: Closing handles can cause application or system instability.
-y Don't prompt for close handle confirmation.
-s Print count of each type of handle open.
-u Show the owning user name when searching for handles.
-p Dump handles belonging to process (partial name accepted).
name Search for handles to objects with <name> (fragment accepted).
-nobanner Do not display the startup banner and copyright message.

No arguments will dump all file references.

C:\>
C:\>
C:\>handle /? > %temp%\hout.txt

Nthandle v4.22 - Handle viewer
Copyright (C) 1997-2019 Mark Russinovich
Sysinternals - www.sysinternals.com

C:\>
and the help info did go to the hout.txt file.


Redirecting stderr as well

C:\>handle /? > %temp%\hout1.txt 2> %temp%\hout2.txt

C:\>

and that did create two files, one with help info, the other just the program version & copyright lines.


I notice that the lines c&p from the terminal window start "Nthandle..." which surprised me a little as I expected them to start just "Handle" or "handle", and wondered if that's related to the weird output lines starting with "N". Incidentally those didn't get generated by bbcbasic.exe a line at a time, but two or three chars at a time. Might it be generating unicode rather than DOS/OEM (for which I may have the terminolgy wrong because I'm used to ASCII output) single bytes?
Hated Moron

Re: Help understanding complaint

Post by Hated Moron »

JeremyNicoll wrote: Sun 19 Mar 2023, 15:31 C:\>"C:\Users\--myuserid--\Downloads\bbcbasic_console_win64\bbcbasic.exe" "sortdemo.bbc"
?[6n?[6nB?[6nB?[6nC?[6n ?[6nB?[6nA?[6nS?[6nI?[6nC?[6n ?[6nf?[6no?[6nr?[6n ?[6nW?[6ni?[6nn?[6n6?[6n4?[6n ?[6nC?[6no?[6nn?[6ns?[6no?[6nl?[6ne?[6n ?[6nv?
Those are terminal escape sequences, suggesting that you are running a non-standard shell which does not emulate a VT-100 (ANSI) terminal by default. Not really helpful to this discussion!

The relevant page ay my website does say quite explicitly: "The console/terminal is assumed to be VT-100 compatible, which the great majority are, in which case most of the standard BBC BASIC VDU commands behave as expected (with the exception of graphics commands), although text viewports are not supported".