[Gambas-user] auto detect pipe |

Brian G brian at westwoodsvcs.com
Wed Nov 1 18:30:58 CET 2023


The file descriptor has a field that identifies if you are talking to a terminal or not, look at the stream class. 
user the mystream.isterm property I think 

So something like last.isterm or file.in.isterm may work for you returning true or false 


"Failure is the key to success; 
each mistake teaches us something" .. Morihei Ueshiba 
Brian G 

----- On Nov 1, 2023, at 7:44 AM, Bruce Steers <bsteers4 at gmail.com> wrote: 



Thanks Bruce/Jussi 

I think i am getting somewhere. 
i now use a Wait 0.1 in Sub Main() 
this allows Application_Read() to happen before moving on, then in Application_Read() i set a string value. 

then in Main() if the string value has been set then i use it 

Problem was without using Wait 0.1 the Main() sub would run to the end before Application_Read() happened 

Respects 
BruceS 


On Wed, 1 Nov 2023 at 13:39, Jussi Lahtinen < [ mailto:jussi.lahtinen at gmail.com | jussi.lahtinen at gmail.com ] > wrote: 

BQ_BEGIN

No time to think, but I guess "if (isatty(STDIN_FILENO))" would work when translated into Gambas. However, my gut feeling is that you are doing something in non-standard way. 
IE there should be another approach for the desired end result. Why do you need this? 


Jussi 


On Wed, Nov 1, 2023 at 2:36 PM Bruce Steers < [ mailto:bsteers4 at gmail.com | bsteers4 at gmail.com ] > wrote: 

BQ_BEGIN

i have made a command that supports piping using Application_Read() 

Static Public Sub Application_Read() 

$bReading = True 

While Lof(Last) 
$aArgs[0] = Last.ReadLine() 
ProcessString() 
If Not Eof(Last) And If Not $bNewLine Then Print "" 
Wend 

$bReading = False 

End 

it works but i have added an arg -p that if i use -p then the pipe is read. 
Eg. 
echo "This text" | mycommand -p 

can i detect if a pipe is to be used or not automatically? 

Respects 
BruceS 


----[ [ http://gambaswiki.org/wiki/doc/netiquette | http://gambaswiki.org/wiki/doc/netiquette ] ]---- 




----[ [ http://gambaswiki.org/wiki/doc/netiquette | http://gambaswiki.org/wiki/doc/netiquette ] ]---- 

BQ_END



----[ http://gambaswiki.org/wiki/doc/netiquette ]---- 
BQ_END


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20231101/0396c522/attachment-0001.htm>


More information about the User mailing list