473,382 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Redirecting console output in realtime?

Hello,

I have a problem with a DOS EXE that is called by a .Net Winforms
application. I need to redirect the console output into a textbox, but
this should happen in real time, so when new output is written to the
redirected StandardOutput-Reader, I want to catch it immediately and
add it the my textbox.

Now, I have tried everything from threads to invokes, but every time i
call the read/readline/readtoend function in the thread, it suspends at
this point. After the process is finished, my thread goes on and the
output is written to the textbox.

Does anybody have an idea how i can make the thread run the entire
time, without stopping after the first access of standardoutput?

I should add that I use VB 2003, so I am not able to use any of the new
2005 classes.

Here are some code snippets:
(the following code lies in an extra class, outside of the GUI)

'Called from the Form when "start"-button is clicked
Public Sub Start()
'See below for exact code of createProcess()
myProc = createProcess()
myProc.Start()

'New Thread for catching the StandardOutput in realtime
myThread = New Threading.Thread(AddressOf startCatch)
myThread.Name = "ConsoleCatcher"
myThread.IsBackground = True

myThread.Start()

End Sub

'Creates a Process with appropriate settings
Private Function createProcess() As Process
Dim objP As New Process
objP.StartInfo.UseShellExecute = False
objP.StartInfo.RedirectStandardOutput = True
objP.StartInfo.RedirectStandardError = True
objP.StartInfo.CreateNoWindow = True
objP.StartInfo.WorkingDirectory = Application.StartupPath

objP.StartInfo.FileName = myFile
objP.StartInfo.Arguments = myArgs

Return objP
End Function
'That's what happens in the output-catching function
Private Sub startCatch()
Try
Dim strLine As String

Do While Not myProc Is Nothing
'The Thread stops while executing the line below for the
first time.
'It continues normally after the Process belonging to the
StandardOutput has finished...
strLine = myProc.StandardOutput.ReadLine()
If strLine <> "" And strLine <> Nothing Then

'Event caught by the Form
RaiseEvent ConsoleOut(Me, New
DataReceivedEventArgs(strLine))
End If

Loop

'See if there's anything left
strLine = myReader.ReadToEnd
If strLine <> Nothing And strLine <> "" Then
RaiseEvent ConsoleOut(Me, New
DataReceivedEventArgs(strLine))
End If
Catch
End Try

End Sub
Any help is highly appreciated. Thanks alot! :-)

Bye,
Markus

Nov 21 '05 #1
5 6143
"Markus S." <sn****@virtualsneets.de> schrieb:
I have a problem with a DOS EXE that is called by a .Net Winforms
application. I need to redirect the console output into a textbox, but
this should happen in real time, so when new output is written to the
redirected StandardOutput-Reader, I want to catch it immediately and
add it the my textbox.

Now, I have tried everything from threads to invokes, but every time i
call the read/readline/readtoend function in the thread, it suspends at
this point. After the process is finished, my thread goes on and the
output is written to the textbox.


<URL:http://www.palmbytes.de/content/dotnet/console.htm>
<URL:http://dotnet.mvps.org/dotnet/samples/misc/#RedirectConsole>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2
Markus,

Any problem that I show you this sample instead of looking to your code (I
made it in this way now, tested it however changed some things for the page
so watch errors because of that changing).

http://www.windowsformsdatagridhelp....b-23cab5aa1049

I hope this helps,

Cor
Nov 21 '05 #3
Hi again,

the first example from
http://www.palmbytes.de/content/dotnet/console.htm is almost the same I
did. and it behaves the way my app does :-)

Maybe I have to specify my problem more exactly.

I am writing a .net frontend for cabarc.exe which created cab archives.

now, let's assume I call the exe with a filelist of 20 files. when i
use the standard console output, the screen is updated after every file
(i can watch the progress in real time, as i get a line saying "file x
added to archive"). when i redirect the output and start cabarc, I
won't get a response from standardoutput.readline until the exe has
finished running...
Slowly it makes me belive that this behavior is just the way the
process class works (waiting until the underlying exe-process is
finished and then redirecting the whole bunch of lines in one step)...

or is there any workaround for this maybe?

But thanks already for the help everybody!

Nov 21 '05 #4
Markus,

Did you beside that palmbytes sample as well tried the sample I made for
you?

Cor
Nov 21 '05 #5
Hello Markus,
hope to find someone with the same mine problem ;)

First of all, i want to tell you of i'm searching for an answer for a long , very long time....

I tryed, like you, to use Cabarc, but my first purpose is to use the redirection in realtime with GoldenHawk DAO burning technology...

As you know most simple software is able to send realtime output to the VB redirector. Most people try to help us in this wrong way. They don't know the existing of some particular dos.exe softwares which not show the output immediately, or don't show it at all untill the end...(cabarc is a valid example)

Please sorry for my bad english, i'm italian...

Anyway i coded a special software which is able to do it...

Simple: i builded a Console application which launch a DOS.exe software and read its output realtime by directly reading the screen.....there are some useful APIs to do it.... and it works 100%..(also in hidden mode)

My software SubSonic Music Burner does it perfectly...

The only issue is on how to pass data beetween the Console Application 8Not the EXE, but the Console application i builded to read the EXE output) and the main visual basic project, the form....
I'm using right now the windows registry, but i hope to really be able to find a better way, because this way is frustrating and a little slow....

My email is stefano@subsonic.it and you can find me here if you need the code. in exchange i hope you will let me know if you will find a real way to get the output realtime with the simple standard redirection....

Please Note, i found the new and awesome new feature within visual basic 2005 express which read data asyncronously from the output. This is cool but unfortunately the unable to get it realtime remain inalterated :D ...
Another cool info is of the StandarError is able to show it realtime....i think it have a different PIPE buffer size...Anyway at this time only the LAME Mp3 tools is using the standard error to show realtime the progress...

I hope i wiil able to help you exactly like you will be able to help me in the future...

Stefano
May 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christophe HELFER | last post by:
hi, I have some problem with redirecting input and output from a process. I can only use VB language (sorry...) Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) ...
0
by: serge desmedt | last post by:
Hi, Where about to start using Unit Testing for dotNet. I have experimented with the NUnit framework and have the following question: According to the documentation of NUnit , using the...
15
by: Matt Burland | last post by:
I'm having a problem with redirecting the StandardOutput of a process that I use to run a DOS program in my application. The problem is that I when I start my process (which I do in a separate...
2
by: Jacek | last post by:
Hello! My application has to use external native library writing to stdout and stdin. My goal is to redirect output within running process (no chance to do that in child process - Process class...
5
by: vijaynats | last post by:
Hi I created a windows app to run a dos batch file (which takes around 5mins to complete and generates lots of output messages on the console in the meantime)and i used RedirectStandardOuput to...
5
by: Tim | last post by:
Hi I am running a console program through my own VB front end. I am redirecting the StandardOut and StandardInput streams to and from textboxes so that the VB front end acts like a console. My...
6
by: Christophe Helfer | last post by:
hi, I have some problem with redirecting input and output from a process. Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) command line utility as redirecting its...
3
by: Sudesh | last post by:
Hi, I am a newbie to C# and Im trying to redirect standard input, output and error of a console program written in C (MS VC 6.0) to a textbox on a form. The code for the redirecting looks like...
3
by: pratap | last post by:
I have an application which periodically gives me an output of sonar values .However i am unable to view the values as they get replaced by the new ones below in realtime and are displayed after...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.