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
how to search in rxmemory...
by
rcmz
[
Today
at 10:19:54 pm]
Configure JCF messages
by
GordonFindlay
[
Today
at 10:16:19 pm]
Poll: Watches and Display...
by
Martin_fr
[
Today
at 10:15:08 pm]
Dialog ShowModal and an i...
by
d7_2_laz
[
Today
at 09:51:39 pm]
JEDI error but unit compi...
by
Thaddy
[
Today
at 09:30:33 pm]
Understanding and adjusti...
by
circular
[
Today
at 09:09:56 pm]
Controlling the behavior ...
by
wp
[
Today
at 08:29:28 pm]
Offical launch of the 1 B...
by
Gustavo 'Gus' Carreno
[
Today
at 08:21:29 pm]
how to change the color f...
by
wp
[
Today
at 07:23:58 pm]
Dynarray initialization p...
by
Thaddy
[
Today
at 06:30:12 pm]
Project fails on run but ...
by
dseligo
[
Today
at 05:30:42 pm]
Zeos components. Had to c...
by
Fantablup
[
Today
at 04:17:13 pm]
[SOLVED] Completion box s...
by
furious programming
[
Today
at 04:12:26 pm]
[LAMW] How to create a ca...
by
af0815
[
Today
at 03:48:16 pm]
Complex package installat...
by
wp
[
Today
at 03:38:16 pm]
A "leisure" question on W...
by
gidesa
[
Today
at 03:17:10 pm]
Curling Pythagoras Tree: ...
by
AlexTP
[
Today
at 03:07:53 pm]
[SOLVED] Combined pointer...
by
CM630
[
Today
at 02:48:41 pm]
Using KeyPress event, how...
by
Zvoni
[
Today
at 02:24:42 pm]
a Unit problem?
by
Thaddy
[
Today
at 01:56:12 pm]
Any upgrades to fpWeb pag...
by
marcov
[
Today
at 12:50:25 pm]
Help needed with Cairo / ...
by
Roland57
[
Today
at 12:25:16 pm]
IDE instability on Raspbe...
by
rvk
[
Today
at 10:37:14 am]
Boleeman's projects are p...
by
AlexTP
[
Today
at 10:18:04 am]
Your best UI design - con...
by
circular
[
Today
at 09:36:11 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Linux: How to detect whether STDOUT was redirected? (Read 3825 times)
Hartmut
Hero Member
Posts: 742
[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: 742
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: 14205
Probably until I exterminate Putin.
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
Specialize a type, not a var.
Thaddy
Hero Member
Posts: 14205
Probably until I exterminate Putin.
Re: Linux: How to detect whether STDOUT was redirected?
«
Reply #5 on:
September 28, 2018, 10:05:13 pm »
Alex , posts crossed.
Logged
Specialize a type, not a var.
Hartmut
Hero Member
Posts: 742
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