[Gambas-user] using 2>redirect with Exec?
Brian G
brian at westwoodsvcs.com
Sun Aug 8 17:23:17 CEST 2021
I added a text area called Errormsg to your project, and here is the code to get error messages and process them from your app:
' Gambas class file
Extern dup2(OldFD As Integer, newfd As Integer) In "libc:6"
Private Writer As File
Private Reader As File
Private restore As File
Public Sub _new()
Writer = Open Pipe "/tmp/testpipeout" For Write
restore = File.Err
dup2(Writer.handle, 2)
Reader = Open Pipe "/tmp/testpipeout" For Read Watch
End
Public Sub _free()
Close Writer
Close Reader
dup2(restore.handle, 2)
End
Public Sub Form_Close()
Quit 0
End
Public Sub file_read()
Dim buffer As String
buffer = Read #Last, -Lof(Last)
ErrorMsgs.text &= "From Error Handler :" & Quote(buffer) & "\n"
ErrorMsgs.Refresh()
End
Public Sub Button1_Click()
Print "Something"
Wait
End
"Failure is the key to success;
each mistake teaches us something" .. Morihei Ueshiba
Brian G
----- On Aug 8, 2021, at 2:43 AM, Bruce Steers <bsteers4 at gmail.com> wrote:
> oooh , that's brilliant , Cheers Brian :)
> I removed the dup2(dummy.Handle, 1) as it's only the gtk warnings i want to
> suppress.
> Now i just have to figure out how to read the error text as it comes through and
> show anything that's not a gtk message.
> almost had it using a pipe but it was flawed :(
> Thank you , much better than my app launching itself twice :)
> BruceS
> On Sun, 8 Aug 2021 at 03:06, Brian G < [ mailto:brian at westwoodsvcs.com |
> brian at westwoodsvcs.com ] > wrote:
>> Hi bruce,
>> Just notices this new thread
>> Replied to the other one but here it is again
>> Add this to the startup class of you application
>> Extern dup2(OldFD As Integer, newfd As Integer) In "libc:6"
>> Static Dummy As File
>> Static Public Sub _init()
>> dummy = Open "/dev/null" For Write
>> dup2(dummy.Handle, 1)
>> dup2(dummy.handle, 2)
>> End
>> No need for any other fiddles
>> "Failure is the key to success;
>> each mistake teaches us something" .. Morihei Ueshiba
>> Brian G
>> ----- On Aug 7, 2021, at 5:05 PM, Jussi Lahtinen < [
>> mailto:jussi.lahtinen at gmail.com | jussi.lahtinen at gmail.com ] > wrote:
>>> No, that is for terminal. You must use "Output to" and "Error To" keywords.
>>> [ http://gambaswiki.org/wiki/lang/errorto |
>>> http://gambaswiki.org/wiki/lang/errorto ]
>>> Jussi
>>> On Sun, Aug 8, 2021 at 2:29 AM Bruce Steers < [ mailto:bsteers4 at gmail.com |
>>> bsteers4 at gmail.com ] > wrote:
>>>> I cannot get redirect working with Exec. Is it possible?
>>>> Ie..
>>>> Shell "/run/mycommand 2>&1"
>>>> works as expected and redirects error text to stdout.
>>>> Exec ["/run/mycommand", "2>&1"]
>>>> does not redirect and only sends '2>&1' as an argument to /run/mycommand.
>>>> Is there a way to redirect with Exec or will i have to Shell it?
>>>> For some reason i am under the impression it is better to use Exec over Shell if
>>>> possible?
>>>> Thanks in advance
>>>> 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 ] ]----
>> ----[ [ http://gambaswiki.org/wiki/doc/netiquette |
>> http://gambaswiki.org/wiki/doc/netiquette ] ]----
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210808/fa99388b/attachment.htm>
More information about the User
mailing list