Recent

Author Topic: Reading from a text file  (Read 3705 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 18791
  • Glad to be alive.
Re: Reading from a text file
« Reply #15 on: August 29, 2024, 10:43:55 am »
Aside: replacing crt with ptccard solves many crt unit related problems without code changes.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Reading from a text file
« Reply #16 on: August 29, 2024, 03:39:27 pm »
Except for the case where the editor/plug-in does not catch error output but only stdout.
Yes, but even then I'd expect a once-bitten beginner to output messages using a standard WriteLn() before learning to use stderr for that sort of thing.
Yes. Almost ofc I would say  :)

With the knowledge that I do not know anything about the editor nor the plugin I would even suggest to start experimenting their behaviour with the infamous hello world.

What a newcomer might perhaps not know about is the separation of stdout and stderr and as a consequence also not know about that whenever an exception is raised (such as in the case the file cannot be found for opening) that stderr is used.


As an addition to TS (because of the specific remark about the startup directory and (any) program not working in such a case):

You can start a command-line program from any current working directory.

Let's say there is a program named "hello" located in the directory "/media/external/examples/fpc/helloworld" and when a terminal is opened it tells us that the current working directory is "/user/username".

There are two possible scenario's, start the program directly by executing it: "./media/external/examples/fpc/helloworld/hello" in which case the current working directory of the program itself will still be "/user/username" or start the program by changing the current working directory first with: "cd /media/external/examples/fpc/helloworld" and then executing the program: "./hello".

There is distinct difference between the two. In the first case either the user has to take care of providing a filename with inclusion of the full path or the program needs to change the current working directory before opening the file (in case no full path was provided). See for example chdir.

In the second case the use already changed the current working directory manually and so passing any filename will first try to open the file in that directory.

A well written execution plugin is required to support both methods of execution.


fwiw: That is one of the reasons why a terminal/shell usually (by default) shows you the current working directory as a prompt: to make sure there is not any misconception on what the actual current working directory is.

But anyhows @TS: glad you were able to solve your issue and thank you for reporting back  8-)

Quote
Quote
The program in its current form should be able to run without errors when providing a full path and filename to the datafile.
It should, but even then there's a possibility that the wrapper program (or associated plugin etc.) would do something silly: start in the wrong directory, use an unexpected directory separator, etc.
Yes, that was exactly the use case I was attempting to refer to because after having watched a small video tutorial about the plugin there seem to be a specific option for the plugin that can be checked to "start" the program in the directory where the executable is located.

Quote
Quote
This is why proper error handling is kinda important  ;D
Yes, but be honest: we've all been there.
That's a fact  :) (or actually  :-[ )
« Last Edit: August 29, 2024, 03:46:42 pm by TRon »
Today is tomorrow's yesterday.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8551
Re: Reading from a text file
« Reply #17 on: August 29, 2024, 05:16:09 pm »
A well written execution plugin is required to support both methods of execution.

The bottom line is that just because a program exposes a plugin API expressed in Python, Lisp, VBA or (potentially) Pascal, the average user should not automatically assume that he's become a programming demiurge.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018