Recent

Author Topic: RuntimeError 103 File not open  (Read 5507 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 17668
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: RuntimeError 103 File not open
« Reply #30 on: July 20, 2025, 05:02:47 pm »
On Lazarus, there is a real terminal emulation at work. One of the virtual pts devices under ptmx control.
Btw I am missing a function in Baseunix:
Code: Pascal  [Select][+][-]
  1. function ttyname(fd: cint): PChar; cdecl; external 'c';
  2. // and my be
  3. {$if defined(unix) and not declared(STDIN_FILENO)}
  4. const
  5.   STDIN_FILENO = 0;
  6.   STDOUT_FILENO = 1;
  7.   STDERR_FILENO = 2;
  8. {$endif}
  9.  
  10. function fpttyname(fd: integer):string;
  11. var
  12.   p:PChar;
  13. begin
  14.   p:=ttyname(STDIN_FILENO );
  15.   Setstring(result,p, strlen(p);
  16. end;
I could not find it elsewhere.



« Last Edit: July 20, 2025, 05:05:12 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12375
  • FPC developer.
Re: RuntimeError 103 File not open
« Reply #31 on: July 20, 2025, 07:01:03 pm »
Ttyname is in unit termio.

And linking to libc is not allowed in baseunix anyways.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6087
  • Compiler Developer
Re: RuntimeError 103 File not open
« Reply #32 on: July 20, 2025, 09:40:21 pm »
That on Windows an error is thrown if a console is missing is simply an incompatibility with Linux and can be fixed.

It doesn't matter that it's an incompatibility to Linux. It would be an incompatiblity to Windows, Delphi and any other language working on that system allowing for development of GUI applications on Windows. And that is much more important, namely that the applications behave nicely like citizens of the system in question and by default a console application does not. Windows is not Linux. If you want Unix-like behavior on Windows then use Interix/Services for Unix Applications (till 7) or WSL (starting from 10).

Thaddy

  • Hero Member
  • *****
  • Posts: 17668
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: RuntimeError 103 File not open
« Reply #33 on: July 21, 2025, 10:22:54 am »
I do all that except using interix, although I used the old posix layer in the past.
The point I don't get is that Lazarus and Delphi willingly expose the Windows programmer and user to preventable inconveniences.
C# does not seem to do that in GUI apps, it discards the output, effectively using a stringwriter that wraps to System.IO.TextWriter.Null (info from Microsoft) that makes the above arguments against largely invalid.
Like my code, invalid writes in C# are silently ignored.
Anyway, consider that part of the question closed. I simply run my 'NUL' unit on Windows - the same as Microsoft does in C# -if I want that version to match the linux version of my programs. Or want to be C# compatible.... :D ;) ;D
https://forum.lazarus.freepascal.org/index.php/topic,71779.msg561039.html#msg561039

GUI's in python (tested tkinter) also silently ignore writes, so has a valid and open IO device too.

So I apply it to releases, if anything to prevent things that lead to the original question: console writes originating from external libraries.
The only thing left for me to decide is to set IsConsole to true or leave IsConsole false. The latter looks the better option.
« Last Edit: July 21, 2025, 01:43:36 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

gues1

  • Full Member
  • ***
  • Posts: 158
Re: RuntimeError 103 File not open
« Reply #34 on: July 21, 2025, 02:48:40 pm »
So I apply it to releases, if anything to prevent things that lead to the original question: console writes originating from external libraries.

So, if an external library send spam via HTTP you will lock the internet access of the application since you MUST use this lib ?  :o

If you like C# and want that FPC and Lazarus agree with it, you also agree with inline var that C# use ... and it also compatible with Delphi :D

This now it's OT but I think that talknig about compatibility with other program languages (topic about WINDOWS OS, not foreign languages) it's a nosense.

Thaddy

  • Hero Member
  • *****
  • Posts: 17668
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: RuntimeError 103 File not open
« Reply #35 on: July 21, 2025, 02:54:16 pm »
No that has nothing to do with it: I just tested some popular GUI builders and concluded after consulting Microsoft that Lazarus is pretty much on its own here. That was the point in the first place.
I have nothing against quirks, but this is at least a quirk and seems unique to Delphi and Freepascal.
So I decided to include my solution in most of my projects.
Remember the original question, where third-party libraries run havoc????
I have not seen one valid reason not to do so after I verified some of the competition.
Not even the explanation by @PascalDragon, which merely outsets why it is the case.
Not the exception position from mainstream that Lazarus takes just for Windows.
I am fine leaving it as is under mode delphi.  >:(
Only I will add the unit anyway.
Deniers seem not to grasp what needs to be done.

I suspect Java also behaves like C# and Pyton with tkinter. Gonna test that and report back.
« Last Edit: July 21, 2025, 03:07:33 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018