|
-
Feb 5th, 2011, 11:10 AM
#1
Thread Starter
Hyperactive Member
Last edited by Cyb3rH4Xter; Feb 5th, 2011 at 11:14 AM.
-
Feb 5th, 2011, 11:58 AM
#2
Re: Console.UpdateText?
You are calling ReadLine, which reads text up to the next line break. ReadLine doesn't return until a line break is entered. Presumably whatever they are outputting doesn't contain any line breaks. Try calling one of the other reading methods that doesn't rely on a line break.
-
Feb 5th, 2011, 01:08 PM
#3
Thread Starter
Hyperactive Member
Re: Console.UpdateText?
 Originally Posted by jmcilhinney
You are calling ReadLine, which reads text up to the next line break. ReadLine doesn't return until a line break is entered. Presumably whatever they are outputting doesn't contain any line breaks. Try calling one of the other reading methods that doesn't rely on a line break.
thx for answer,
I tried the ReadToEnd, though it only reads when I close the other process.
I tried using the Read and ReadBlock though I don't understand how they work? 
EDIT: I took a try on this:http://www.codeproject.com/KB/thread...chprocess.aspx
and it can read okay, so I will use that method instead (adding handlers for stdoutput received).
Last edited by Cyb3rH4Xter; Feb 5th, 2011 at 01:29 PM.
-
Feb 5th, 2011, 01:28 PM
#4
-
Feb 5th, 2011, 01:44 PM
#5
Thread Starter
Hyperactive Member
Re: Console.UpdateText?
 Originally Posted by Pradeep1210
Great blog!
I will try to use that method instead, more simple. But I got one problem, I don't know to add handlers for the DataReceived in C# :S
-
Feb 5th, 2011, 07:57 PM
#6
Re: Console.UpdateText?
 Originally Posted by Cyb3rH4Xter
But I got one problem, I don't know to add handlers for the DataReceived in C#
If you add the Process object to the form in the designer then you can use the Properties window to add the event handlers, just like any other control or component. If you want to add them in code then you do it like this:
csharp Code:
someObject.SomeEvent += new EventHandler(SomeMethod);
If you start typing a line like that, once you type the = then VS will help you from there.
-
Feb 6th, 2011, 04:40 AM
#7
Thread Starter
Hyperactive Member
Re: Console.UpdateText?
 Originally Posted by jmcilhinney
If you add the Process object to the form in the designer then you can use the Properties window to add the event handlers, just like any other control or component. If you want to add them in code then you do it like this:
csharp Code:
someObject.SomeEvent += new EventHandler(SomeMethod);
If you start typing a line like that, once you type the = then VS will help you from there.
Thx, halfway through now 
It won't accept this:
Code:
prc.OutputDataReceived += new DataReceivedEventHandler(OutputDataReceived);
Code:
private void OutputDataReceived(Object sender, System.Diagnostics.DataReceivedEventArgs e)
{
Console.Write(e.Data);
}
Error:
Code:
An object reference is required for the non-static field, method, or property 'QuickBrake.Program.OutputDataReceived(object, System.Diagnostics.DataReceivedEventArgs)'
EDIT: Solved by changing to private static void thx for help
EDIT2: I am just curious, can I do like them and just kind of update the text, not write a new line or anything like that?
LASTEDIT: Solved that too, adding \r to the beginning of the string moves the cursor back and makes it overwrite last (Console.Write("\r Hello")
Last edited by Cyb3rH4Xter; Feb 6th, 2011 at 04:49 AM.
-
Feb 7th, 2011, 02:12 PM
#8
Re: [RESOLVED] Console.UpdateText?
Whew this harkens back to my old DOS programming days.
In the DOS console (not the CMD Shell - they're different) one can send BIOS Interop codes to move the cursor around the shell. You can not only rewrite the line you're on - I used to write information at the top line and bottom line of the screen with every update and then put the cursor back to where it started.
Those were the days! (I wrote in Fortran then!!)
The escape characters you would use for that are listed here, but are a bit cryptic to puzzle out:
http://local.wasp.uwa.edu.au/~pbourk...formats/ascii/
(Scroll down to "ANSI Standard (X3.64) Control Sequences For Video Terminals And Peripherals In Alphabetic Order By Mnemonic")
The escape sequence to set a position would be:
Code:
//Code not tested
//Let's set the position to 3, 12
byte HorizontalOffset = (byte) 3;
byte VerticalOffset = (byte) 12;
char[] MovePosition = {27, '[', HorizontalOffset, ';', VerticalOffset, 'H'};
Console.Write(MovePosition);
Though I can't test this right now (about to be away from the computer). And it may not work in the console at all anymore.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Feb 7th, 2011, 05:48 PM
#9
Re: [RESOLVED] Console.UpdateText?
Haha. They saw me coming. The code above doesn't work (it just displays garbage which is what I expected)
... but the following does work:
Code:
Console.SetCursorPosition(3, 12);
Console.Write("Test");
Console.ReadKey();
Talk about elephant gun and fly...
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Feb 7th, 2011, 05:54 PM
#10
Re: [RESOLVED] Console.UpdateText?
To extend the example, this writes " Well?" then backs up, overwrites the space with an "Sw" (Making it "Swell?") and returns the input back to where it was (after the question mark).
Code:
Console.WriteLine("Test Line");
Console.Write(" Well?");
int Horizontal = Console.CursorLeft;
int Vertical = Console.CursorTop;
//Upper Left is 0, 0
Console.SetCursorPosition(0, Vertical);
Console.Write("Sw");
Console.SetCursorPosition(Horizontal, Vertical);
Console.ReadKey();
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Feb 8th, 2011, 01:28 PM
#11
Thread Starter
Hyperactive Member
Re: [RESOLVED] Console.UpdateText?
I see, great code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|