Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Operating Systems
»
Linux
»
[SOLVED] Linux: How to detect whether STDOUT was redirected?
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Debian removes FPC/Lazaru...
by
dsiders
[
Today
at 06:34:55 pm]
Status of FPC 3.4.0 or FP...
by
440bx
[
Today
at 05:10:03 pm]
LCL Web Native with D2Bri...
by
xinyiman
[
Today
at 04:52:10 pm]
Log in to web Data with U...
by
rvk
[
Today
at 03:23:29 pm]
Free Pascal for a small e...
by
devEric69
[
Today
at 02:51:51 pm]
Transparent Form: Some Th...
by
Boleeman
[
Today
at 02:34:08 pm]
Notetask 1.1.0 - Free cro...
by
AlexanderT
[
Today
at 02:33:56 pm]
Rolling releases Lazarus[...
by
marcov
[
Today
at 02:07:36 pm]
lazarus IDE anchordock ba...
by
szlbz
[
Today
at 12:53:12 pm]
Upload multipart POST req...
by
OH1KH
[
Today
at 11:53:17 am]
Ininside ProjectSession, ...
by
d2010
[
Today
at 10:34:50 am]
Recommendations for wasm3...
by
temp0
[
Today
at 03:47:38 am]
Lazarus for Windows on aa...
by
msintle
[
Today
at 01:02:01 am]
ListBox MeasureItem
by
jamie
[February 05, 2026, 11:02:02 pm]
Feature announcement: Fun...
by
PascalDragon
[February 05, 2026, 09:29:34 pm]
Improved FPC JSON-RPC sup...
by
PascalDragon
[February 05, 2026, 09:15:07 pm]
C-specific record functio...
by
440bx
[February 05, 2026, 08:38:23 pm]
What is a status of fpGUI...
by
inky
[February 05, 2026, 06:55:54 pm]
[SOLVED] How to scroll a ...
by
Hartmut
[February 05, 2026, 03:36:11 pm]
Default, Manual Initializ...
by
Thaddy
[February 05, 2026, 03:06:23 pm]
Does FreePascal have a WM...
by
CM630
[February 05, 2026, 01:02:14 pm]
Label collision on X axis...
by
PeterX
[February 05, 2026, 11:25:33 am]
how to run code in backgr...
by
CM630
[February 05, 2026, 10:16:31 am]
PadXml 1.0.1 – Portable A...
by
AlexanderT
[February 05, 2026, 10:11:11 am]
Lazaris IDE v4.4 - extrem...
by
dbannon
[February 05, 2026, 04:58:00 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Linux: How to detect whether STDOUT was redirected? (Read 4523 times)
Hartmut
Hero Member
Posts: 1054
[SOLVED] Linux: How to detect whether STDOUT was redirected?
«
on:
September 28, 2018, 06:38:43 pm »
I want a function which tells me, whether STDOUT of my console program was redirected or not like
myprogram > outfile
In
http://forum.lazarus.freepascal.org/index.php/topic,41936.0.html
there is a solution for Windows, but I need it for Linux (Ubuntu 18.04). Can somebody help?
I'm an absolute beginner on Linux, so please be not to short in your answer. Thanks a lot in advance.
«
Last Edit: September 28, 2018, 10:13:50 pm by Hartmut
»
Logged
mpv
Newbie
Posts: 6
Re: Linux: How to detect whether STDOUT was redirected?
«
Reply #1 on:
September 28, 2018, 09:08:53 pm »
You can check stdout is a terminal using isatty() function. If not then stdout is redirected
Logged
Hartmut
Hero Member
Posts: 1054
Re: Linux: How to detect whether STDOUT was redirected?
«
Reply #2 on:
September 28, 2018, 09:41:21 pm »
That sounds interesting. But I don't find this function, in which unit is it?
http://www.math.uni-leipzig.de/pool/tuts/FreePascal/units/node12.html#SECTION0012369000000000000000
says it is in unit "Linux", but I still get a compilation error: Identifier not found "IsATTY"
Thanks for your help.
Logged
alex256
New Member
Posts: 24
Re: Linux: How to detect whether STDOUT was redirected?
«
Reply #3 on:
September 28, 2018, 09:50:45 pm »
Code: Pascal
[Select]
[+]
[-]
uses
termio
;
Logged
Thaddy
Hero Member
Posts: 18726
To Europe: simply sell USA bonds: dollar collapses
Re: Linux: How to detect whether STDOUT was redirected?
«
Reply #4 on:
September 28, 2018, 10:04:33 pm »
Code: Pascal
[Select]
[+]
[-]
{$ifdef fpc}{$mode delphi}{$H+}{$endif}
uses
termio
;
begin
writeln
(
IsATTY
(
output
)
)
;
end
.
Logged
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...
Thaddy
Hero Member
Posts: 18726
To Europe: simply sell USA bonds: dollar collapses
Re: Linux: How to detect whether STDOUT was redirected?
«
Reply #5 on:
September 28, 2018, 10:05:13 pm »
Alex , posts crossed.
Logged
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...
Hartmut
Hero Member
Posts: 1054
Re: Linux: How to detect whether STDOUT was redirected?
«
Reply #6 on:
September 28, 2018, 10:13:23 pm »
It works! Thanks a lot to all who helped me.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Operating Systems
»
Linux
»
[SOLVED] Linux: How to detect whether STDOUT was redirected?
TinyPortal
© 2005-2018