You are not logged in.

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

1

Sunday, July 27th 2014, 4:34pm

Redirecting standard output and standard error, to text boxes

Assume the form is named frmTest, and you have 2 text boxes, frmTest.txtOut and frmTest.txtErr

In the main proc,


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Import java#io#PrintStream


Public psError As PrintStream
Public psOut As PrintStream


'...
'...
'...



Public Sub main(ByJava args() As String)
'...
'...
Dim opStreamErr As clsOutputStream
Dim opStreamOut As clsOutputStream
'...
'...

frmTest.SetDefaultClose()
frmTest.Show()



opStreamErr = New clsOutputStream( frmTest.txtError )
psError = New PrintStream( opStreamErr )


opStreamOut = New clsOutputStream( frmTest.txtOutput )
psOut = New PrintStream( opStreamOut )

System.setErr( psError )
System.setOut( psOut )


System.out.println( "Testing, what should be standard output" )
System.err.println( "Testing what should be standard error" )
   
End Sub




Also, create a class clsOutputStream, and set the Superclass to java/io/OutputStream. In the class, put this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Import java#io#OutputStream
Import VB#TextBox


Dim txtJBTextArea As VB#TextBox


Public Sub clsOutputStream( txtJB As VB#TextBox )

txtJBTextArea = txtJB

End Sub


Public Sub write( nOutputCharacter As Integer )

Me.writeOverridable( nOutputCharacter )

End Sub

Public Sub writeOverridable( nOutputCharacter As Integer )
Dim cOutputCharacter As String
cOutputCharacter = Chr( nOutputCharacter )

txtJBTextArea.AppendText( cOutputCharacter )


End Sub

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

2

Monday, July 28th 2014, 9:25am

Hey there,

nice sample on how to redirect an output stream.
THANKS... :thumbup:

BY using

Quoted

java/io/OutputStream


as superclass for clsOutputStream you are allready overriding every generic method and property that you are addressing!
So...

Jabaco Source

1
2
3
4
5
6
7
8
9
10
Public Sub write( nOutputCharacter As Integer )

   'Me.writeOverridable( nOutputCharacter )

   Dim cOutputCharacter As String
   cOutputCharacter = Chr( nOutputCharacter )

   txtJBTextArea.AppendText( cOutputCharacter )

End Sub


will do the job!


Dani

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

3

Monday, July 28th 2014, 2:11pm

Hey there,

nice sample on how to redirect an output stream.
THANKS... :thumbup:

BY using

Quoted

java/io/OutputStream


as superclass for clsOutputStream you are allready overriding every generic method and property that you are addressing!
So...

Jabaco Source

1
2
3
4
5
6
7
8
9
10
Public Sub write( nOutputCharacter As Integer )

   'Me.writeOverridable( nOutputCharacter )

   Dim cOutputCharacter As String
   cOutputCharacter = Chr( nOutputCharacter )

   txtJBTextArea.AppendText( cOutputCharacter )

End Sub


will do the job!


Dani

Yes, I originally overrode the the write method, with just an substitute write method. But then noticed an earlier Jabaco post, which injected a separate 'foooverridable' method. It seemed like a neat way to document that the class was meant to be extended, so it was thrown in.

So, we did it. Now Jabaco users have a way of redirecting standard output/error.

Is there a way to tag these posts, for example with keywords like 'stdout' and 'stderr'?

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

4

Monday, July 28th 2014, 2:22pm

Is there a way to tag these posts, for example with keywords like 'stdout' and 'stderr'?


You might try to change the Thread name -> 'Message Information' -> 'Subject' of your initial post ...

I don't know if that is possible though!?

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

5

Monday, July 28th 2014, 6:08pm

So the forum doesn't actually have tags. Ok, we can leave as is. Hopefully anybody will think to use 'standard output' if 'stdout' doesn't pan out.


Thanks & regards,

Rate this thread
WoltLab Burning Board