Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-01

fpsystem output

12 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rainer Stratmann
When calling for example fpsystem( 'cat /proc/partitions' );
the lines are not beginning at the 1st character of the next line

Instead of
Line1
Line2
Line3
like in the Linux shell

The output is:
Line1
Line2
Line3

and so on

What is the reason?

Reply by email

Michael Van Canneyt
to Rainer Stratmann
Rainer Stratmann wrote 17 lines
When calling for example fpsystem( 'cat /proc/partitions' ); the lines are not beginning at the 1st character of the next line Instead of Line1 Line2 Line3 like in the Linux shell The output is: Line1 Line2 Line3 and so on What is the reason?

Here the output looks OK when executing as-is.

But if you are using the crt unit, that may mess up the terminal. I added crt, and then the output was indeed indented.

Michael.

Reply by email

Mark Morgan Lloyd
to Rainer Stratmann: When calling for example fpsystem( 'cat /proc/partitions' ); the lines are not beginning…
Rainer Stratmann wrote 17 lines
When calling for example fpsystem( 'cat /proc/partitions' ); the lines are not beginning at the 1st character of the next line Instead of Line1 Line2 Line3 like in the Linux shell The output is: Line1 Line2 Line3 and so on What is the reason?

You've not told us what OS etc. you're running. This is the sort of thing I'd expect to see if the program were running on a unix system that generated \n (LF) at the end of each line, but you had a misconfigured terminal emulator that was currently expecting CR LF. You could get this if the terminal emulator were on Windows, but a particular case on any platform is where for some reason the TE or console has been set to raw (or similar) mode; there's commands to sort this out but often the safest way is to restart the session.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Rainer Stratmann
to Michael Van Canneyt: Here the output looks OK when executing as-is. But if you are using the crt unit, that…
Michael Van Canneyt wrote 23 lines
On Mon, 14 Jan 2013, Rainer Stratmann wrote: > When calling for example fpsystem( 'cat /proc/partitions' ); > the lines are not beginning at the 1st character of the next line > > Instead of > Line1 > Line2 > Line3 > like in the Linux shell > > The output is: > Line1 > Line2 > Line3 > > and so on > > What is the reason? Here the output looks OK when executing as-is. But if you are using the crt unit, that may mess up the terminal. I added crt, and then the output was indeed indented.

I also use crt.
Is it possible to change the bevahiour?

Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Rainer Stratmann
Rainer Stratmann wrote 27 lines
Am Tuesday 15 January 2013 08:57:58 schrieb Michael Van Canneyt: > On Mon, 14 Jan 2013, Rainer Stratmann wrote: >> When calling for example fpsystem( 'cat /proc/partitions' ); >> the lines are not beginning at the 1st character of the next line >> >> Instead of >> Line1 >> Line2 >> Line3 >> like in the Linux shell >> >> The output is: >> Line1 >> Line2 >> Line3 >> >> and so on >> >> What is the reason? > > Here the output looks OK when executing as-is. > > But if you are using the crt unit, that may mess up the terminal. > I added crt, and then the output was indeed indented. I also use crt. Is it possible to change the bevahiour?

No.
in order to do it's magic, CRT must control the terminal.

Michael.

Reply by email

Rainer Stratmann
to Michael Van Canneyt
Michael Van Canneyt wrote 31 lines
On Tue, 15 Jan 2013, Rainer Stratmann wrote: > Am Tuesday 15 January 2013 08:57:58 schrieb Michael Van Canneyt: >> On Mon, 14 Jan 2013, Rainer Stratmann wrote: >>> When calling for example fpsystem( 'cat /proc/partitions' ); >>> the lines are not beginning at the 1st character of the next line >>> >>> Instead of >>> Line1 >>> Line2 >>> Line3 >>> like in the Linux shell >>> >>> The output is: >>> Line1 >>> Line2 >>> Line3 >>> >>> and so on >>> >>> What is the reason? >> >> Here the output looks OK when executing as-is. >> >> But if you are using the crt unit, that may mess up the terminal. >> I added crt, and then the output was indeed indented. > > I also use crt. > Is it possible to change the bevahiour? No. in order to do it's magic, CRT must control the terminal.

Are there alternative ways to write something on the screen and to clear the screen?
For example with unit system?

Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Mark Morgan Lloyd
to Rainer Stratmann
Rainer Stratmann wrote 5 lines
> in order to do it's magic, CRT must control the terminal. Are there alternative ways to write something on the screen and to clear the screen? For example with unit system?

In the general case, that's going to be terminal-specific. If you only want stdout (and/or stderr) output you'd need to know what escape sequence to sent to the terminal (possibly with reference to termcap/terminfo- I don't know whether there are libraries to handle this) but if you wanted full control like you get with the FP IDE I think you'd be using the old TurboPower stuff.

In extremis, if you're already invoking an external program and want to clear output after it runs, and if you know that you're running on a unix, you could simply invoke the clear program.

Going back to your original question, I see no reason why you couldn't open and parse e.g. /proc/partitions as an ordinary text file.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Rainer Stratmann: Are there alternative ways to write something on the screen and to clear the screen? For…
Rainer Stratmann wrote 36 lines
Am Tuesday 15 January 2013 13:25:08 schrieb Michael Van Canneyt: > On Tue, 15 Jan 2013, Rainer Stratmann wrote: >> Am Tuesday 15 January 2013 08:57:58 schrieb Michael Van Canneyt: >>> On Mon, 14 Jan 2013, Rainer Stratmann wrote: >>>> When calling for example fpsystem( 'cat /proc/partitions' ); >>>> the lines are not beginning at the 1st character of the next line >>>> >>>> Instead of >>>> Line1 >>>> Line2 >>>> Line3 >>>> like in the Linux shell >>>> >>>> The output is: >>>> Line1 >>>> Line2 >>>> Line3 >>>> >>>> and so on >>>> >>>> What is the reason? >>> >>> Here the output looks OK when executing as-is. >>> >>> But if you are using the crt unit, that may mess up the terminal. >>> I added crt, and then the output was indeed indented. >> >> I also use crt. >> Is it possible to change the bevahiour? > > No. > in order to do it's magic, CRT must control the terminal. Are there alternative ways to write something on the screen and to clear the screen? For example with unit system?

Since you're already executing external commands:
Execute the /usr/bin/clear command ?

Michael.

Reply by email

Rainer Stratmann
to Mark Morgan Lloyd: In the general case, that's going to be terminal-specific. If you only want stdout…
Mark Morgan Lloyd wrote 20 lines
Rainer Stratmann wrote: >> in order to do it's magic, CRT must control the terminal. > > Are there alternative ways to write something on the screen and to clear > the screen? > For example with unit system? In the general case, that's going to be terminal-specific. If you only want stdout (and/or stderr) output you'd need to know what escape sequence to sent to the terminal (possibly with reference to termcap/terminfo- I don't know whether there are libraries to handle this) but if you wanted full control like you get with the FP IDE I think you'd be using the old TurboPower stuff. In extremis, if you're already invoking an external program and want to clear output after it runs, and if you know that you're running on a unix, you could simply invoke the clear program. Going back to your original question, I see no reason why you couldn't open and parse e.g. /proc/partitions as an ordinary text file.

This is one thing.
Another thing are the error messages from freepascal which behave the same then.
And other output messages (for example dhcp service programs).

Isn't it possible to make a function in crt that makes the behaviour wanted? Something like crt.turn_linefeed_on(); or similar.

Reply by email

Michael Van Canneyt
to Rainer Stratmann
Rainer Stratmann wrote 29 lines
Am Tuesday 15 January 2013 13:41:19 schrieb Mark Morgan Lloyd: > Rainer Stratmann wrote: >>> in order to do it's magic, CRT must control the terminal. >> >> Are there alternative ways to write something on the screen and to clear >> the screen? >> For example with unit system? > > In the general case, that's going to be terminal-specific. If you only > want stdout (and/or stderr) output you'd need to know what escape > sequence to sent to the terminal (possibly with reference to > termcap/terminfo- I don't know whether there are libraries to handle > this) but if you wanted full control like you get with the FP IDE I > think you'd be using the old TurboPower stuff. > > In extremis, if you're already invoking an external program and want to > clear output after it runs, and if you know that you're running on a > unix, you could simply invoke the clear program. > > Going back to your original question, I see no reason why you couldn't > open and parse e.g. /proc/partitions as an ordinary text file. This is one thing. Another thing are the error messages from freepascal which behave the same then. And other output messages (for example dhcp service programs). Isn't it possible to make a function in crt that makes the behaviour wanted? Something like crt.turn_linefeed_on(); or similar.

No, it is not.

CRT is simply not meant to be mixed with raw output, and definitely not from other programs. There would be no end to the number of problems.

Michael.

Reply by email

Jonas Maebe
to Rainer Stratmann: This is one thing. Another thing are the error messages from freepascal which behave the…
Rainer Stratmann wrote 5 lines
This is one thing. Another thing are the error messages from freepascal which behave the same then. And other output messages (for example dhcp service programs).

Use TProcess to execute external programs and capture their output. You can then write it using the regular write/writeln routines, which work correctly with the crt unit. See http://wiki.freepascal.org/Executing_External_Programs#TProcess for help.

Jonas

Reply by email

leledumbo
to Rainer Stratmann: Are there alternative ways to write something on the screen and to clear the screen? For…

Crt installs its own driver to control the screen buffer (and it has to be done, no way to escape). You can create your own by using Video unit: http://www.freepascal.org/docs-html/rtl/video/index.html

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/fpsystem-output-tp5712543p5712566.html Sent from the Free Pascal - General mailing list .

Reply by email