Click here to Skip to main content
15,910,211 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, i want to capture characters output from console app!
i have tried all method thats available but cannot capture it until the line is printed!
(read line is not working at all until the line is printed)
Any idea?
Posted

1 solution

No, you certainly did not try "all methods". :-)

The method of capturing is well known, because all IDE need it. Good or bad, but traditionally all compilers and other build tools (like MSBuild.EXE) are created as separate command line applications and run in separate processes by IDE. For example, Visual Studio never builds .NET projects but uses compilers, MSBuild and other tools bundled with every version of (freely redistributable) .NET Framework. Nevertheless, you never see "raw" console, because all the output (in fact, too streams: standard output and standard error) are redirected to UI if the IDE.

You can do it by using the method System.Diagnostics.Process.Start(ProcessStartInfo) with re-directed StandardOutput and StandardError. You should remember to set the flags System.Diagnostics.ProcessStartInfo.RedirectStandardOutput and System.Diagnostics.ProcessStartInfo.RedirectStandardError.

See:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx[^].

You can find a simple code sample for redirection and basic explanations here: http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx[^].

—SA
 
Share this answer
 
v4
Comments
Abhinav S 10-Dec-11 23:26pm    
Of course. 5.
Sergey Alexandrovich Kryukov 10-Dec-11 23:28pm    
Thank you, Abhinav.
--SA
Leecherman 10-Dec-11 23:40pm    
Thanks for your reply.
Yes i have tried that too, but also not working...
here is my code:

Dim myProcess As New Process()
myProcess.StartInfo.FileName = My.Application.Info.DirectoryPath & "\sfv_md5.exe"
myProcess.StartInfo.Arguments = "C:\filename.sfv"
myProcess.StartInfo.WorkingDirectory = My.Application.Info.DirectoryPath
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()
myProcess.BeginOutputReadLine()

AddHandler myProcess.OutputDataReceived, New DataReceivedEventHandler(AddressOf OutputDataReceived)

myProcess.WaitForExit()

This code doesn't work, it only work if the console printed a new line otherwise it will not working.

i have uploaded the console app that i want to capture it's output.
NOTE: i want to capture the progress %% that doesn't printed in new line ( but in cache i think )

http://www.mediafire.com/?6qunr1jgg5t2ypq
Amir Mahfoozi 11-Dec-11 0:05am    
So if you have access to console program try to write the value of progress, for example 10%<enter> 20%<enter> ... so it will work. Sometimes its necessary to get to the result by any available means and after that try to optimize it.
Leecherman 11-Dec-11 0:29am    
no, i cannot access to the console app because it's not mine, and it has 10%~100% PROGRESS
but it doesn't printed in new line, so i cannot capture it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900