How to redirect Console output

55 views
Skip to first unread message

its Win32nipuh

unread,
May 17, 2012, 2:57:13 PM5/17/12
to CS-Script
Example:

I have a .NET UserControl with 2 textboxes.

textBox1.Text contains script which I execute.
I want to get output from all scripts Console.WriteLine() and put it
to the textBox2.Text.
Is it possible somehow?

Thanx,
Regards,
Oleg.

Oleg Shilo

unread,
May 17, 2012, 7:44:26 PM5/17/12
to CS-Script
You do not need to redirect the script console output as the script
writes to the same console as your host process have attached. Thus if
you want to catch console output you need to do it in your host
process. Example is in the the <cs-script>/Samples/runScript.cs. While
this sample demonstrates not hosting the script but rather running it
as a separate process it still shows the console redirection
technique.

Saying that capturing console seems very wrong if you are hosting the
script engine. Because if you do then you can easily exchange the data
between script and host in any direction without resorting to such and
exotic technique as the console output capturing.

See <cs-script>\Samples\Hosting\HostingWithInterfaces\Host.cs sample
and the whole Hosting directory for the "inspiration".

Cheers,
Oleg

its Win32nipuh

unread,
May 18, 2012, 3:16:38 AM5/18/12
to CS-Script
Ah, I see, thanks.
Reply all
Reply to author
Forward
0 new messages