[Gambas-user] OUTPUT TO, stdout and command line usage

T Lee Davidson t.lee.davidson at gmail.com
Wed Aug 25 16:17:12 CEST 2021


On 8/25/21 5:25 AM, bb wrote:
> Seems good, but I am still struggling with getting the entire command
> line including any pipes added by the user. I can get all the options
> and parameters but not anything after a <, > or |.
> Maybe the shell consumes it?
> b
> On Sun, 2021-08-22 at 12:39 +0100, Bruce Steers wrote:
>> I asked the same a little while while ago.
>>
>> File.In.IsTerm
>>
>> Is true if started from terminal.
>>
>> BruceS
>>
>> On Sun, 22 Aug 2021, 10:51 bb, <adamnt42 at gmail.com> wrote:
>>
>>> (Sigh, just when I thought it was OK to release to a "client")
>>>
>>> How can I detect that the user has started a project with CLI
>>> redirects, i.e. gbx3 myproj > ~/somewhere.txt
>>> before I issue an OUTPUT TO in the startup routine?
>>>
>>> They have to come up with new twists on anything don't they!
>>>
>>> bruce
>>>
>>>

Perhaps something like this might do what you need:

Public Sub Form_Open()

   Dim sOutput As String

   Shell Subst("lsof -p &1 -a -d 1 | grep REG", Application.Id) To sOutput
   If sOutput Then 'someone's trying to be sneaky
     TextArea1.Text = Split(sOutput, " ").Last
   Endif

End

Using "-d 1" assumes that any program output redirection will be given the second available file descriptor (zero-indexed). I'm 
not sure that would always be the case, and so "-d 0-3" might be more appropriate. But, then you'd need to process each line 
individually to find the one opened with the write attribute (eg. "1w").


-- 
Lee


More information about the User mailing list