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
IRC channel
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
Demoscene The Champs Crac...
by
Gigatron
[
Today
at 02:26:07 am]
Linux Workspaces -- StayO...
by
dbannon
[
Today
at 02:13:13 am]
Find child controls by na...
by
Joanna
[
Today
at 02:03:50 am]
Assign (textfile) not com...
by
teresa
[
Today
at 01:56:13 am]
How to: create DLL file f...
by
KodeZwerg
[
Today
at 12:57:56 am]
Slow copying of small str...
by
jamie
[
Today
at 12:37:04 am]
location of non visual co...
by
VisualLab
[April 17, 2024, 11:58:55 pm]
For-in loop over constant...
by
Joanna
[April 17, 2024, 11:57:15 pm]
Lazarus editor feature re...
by
440bx
[April 17, 2024, 11:49:08 pm]
InstallAware Using Lazaru...
by
VisualLab
[April 17, 2024, 11:08:24 pm]
How would you define a fi...
by
wp
[April 17, 2024, 11:04:00 pm]
Directx9 with mylogo insi...
by
KodeZwerg
[April 17, 2024, 11:03:54 pm]
Lazarus for Windows on aa...
by
Wallaby
[April 17, 2024, 10:25:46 pm]
Azure sql database will n...
by
dseligo
[April 17, 2024, 10:15:27 pm]
[SOLVED] TDbf table, Leve...
by
1HuntnMan
[April 17, 2024, 10:03:16 pm]
Doomed name
by
Martin_fr
[April 17, 2024, 09:09:52 pm]
lazarus-project_3.2.0-0_a...
by
midigark
[April 17, 2024, 06:09:40 pm]
Text orientation in TMemo...
by
wp
[April 17, 2024, 05:51:25 pm]
TBGRABitmap.TextSize retu...
by
circular
[April 17, 2024, 05:24:04 pm]
BUG REPORT: Unable to gen...
by
gasensor
[April 17, 2024, 05:10:20 pm]
[solved]FP IDE(FP.exe) fa...
by
gasensor
[April 17, 2024, 04:45:40 pm]
Inherits forms and releas...
by
ASerge
[April 17, 2024, 03:37:45 pm]
The weird Rewrite bug
by
Kays
[April 17, 2024, 01:23:40 pm]
FpDebug unexpected Assemb...
by
440bx
[April 17, 2024, 12:54:43 pm]
Arabic text, problem on L...
by
Zaher
[April 17, 2024, 12:34:05 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Linux: How to detect whether STDOUT was redirected? (Read 3880 times)
Hartmut
Hero Member
Posts: 749
[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: 749
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: 14367
Sensorship 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
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.
Thaddy
Hero Member
Posts: 14367
Sensorship 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
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.
Hartmut
Hero Member
Posts: 749
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