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
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
SDL2 image rotation Probl...
by
Fred vS
[
Today
at 01:13:15 am]
Add additional Components...
by
dangersgromit
[
Today
at 12:26:58 am]
Nested declarations insid...
by
440bx
[January 15, 2025, 11:58:39 pm]
File operations blocking ...
by
TRon
[January 15, 2025, 11:39:19 pm]
SetPart ?
by
BubikolRamios
[January 15, 2025, 11:32:19 pm]
TRichMemo High Lighted te...
by
What I can do
[January 15, 2025, 11:20:37 pm]
String replace or add ' ...
by
eldonfsr
[January 15, 2025, 10:23:59 pm]
H2Pas can't handle EXP CA...
by
Dibo
[January 15, 2025, 10:01:03 pm]
Lazarus/FPC Flatpak appli...
by
Chronos
[January 15, 2025, 09:56:54 pm]
The mouse and using ptcgr...
by
TBMan
[January 15, 2025, 09:15:40 pm]
TImage colors incorrect
by
Jonny
[January 15, 2025, 08:51:56 pm]
triple click
by
Zoran
[January 15, 2025, 08:25:18 pm]
const declaration
by
freemind001
[January 15, 2025, 07:54:16 pm]
SDL2: Runtime Error 216 o...
by
TRon
[January 15, 2025, 07:44:59 pm]
Iterator on non-existing ...
by
Warfley
[January 15, 2025, 05:45:03 pm]
Batch "publish" of all pr...
by
MarkMLl
[January 15, 2025, 05:42:45 pm]
[solved] Setting the init...
by
TBMan
[January 15, 2025, 04:28:08 pm]
MQTT Client
by
cdbc
[January 15, 2025, 03:06:25 pm]
Issue getting and setting...
by
d7_2_laz
[January 15, 2025, 02:28:48 pm]
Problem with cell comment
by
kjteng
[January 15, 2025, 02:17:57 pm]
[SOLVED]Troubles when con...
by
bytebites
[January 15, 2025, 01:15:16 pm]
FP crashes after running ...
by
marcov
[January 15, 2025, 10:06:01 am]
Repository mirror and Ind...
by
Thaddy
[January 15, 2025, 10:02:53 am]
how to find application r...
by
Packs
[January 15, 2025, 06:51:05 am]
Hustle - A simple task ma...
by
Wesbat
[January 15, 2025, 12:24:34 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Linux: How to detect whether STDOUT was redirected? (Read 4113 times)
Hartmut
Hero Member
Posts: 891
[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: 891
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: 16322
Censorship about opinions does not belong here.
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
There is nothing wrong with being blunt. At a minimum it is also honest.
Thaddy
Hero Member
Posts: 16322
Censorship about opinions does not belong here.
Re: Linux: How to detect whether STDOUT was redirected?
«
Reply #5 on:
September 28, 2018, 10:05:13 pm »
Alex , posts crossed.
Logged
There is nothing wrong with being blunt. At a minimum it is also honest.
Hartmut
Hero Member
Posts: 891
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