Click here to Skip to main content
15,891,431 members
Home / Discussions / C#
   

C#

 
GeneralRe: Displaying the output of a console application in a windows form. Pin
Luc Pattyn23-May-09 6:02
sitebuilderLuc Pattyn23-May-09 6:02 
AnswerRe: Displaying the output of a console application in a windows form. Pin
Luc Pattyn23-May-09 6:06
sitebuilderLuc Pattyn23-May-09 6:06 
GeneralRe: Displaying the output of a console application in a windows form. Pin
neoflame23-May-09 10:11
neoflame23-May-09 10:11 
GeneralRe: Displaying the output of a console application in a windows form. Pin
Luc Pattyn23-May-09 10:19
sitebuilderLuc Pattyn23-May-09 10:19 
GeneralRe: Displaying the output of a console application in a windows form. Pin
neoflame23-May-09 11:04
neoflame23-May-09 11:04 
AnswerRe: Displaying the output of a console application in a windows form. Pin
Luc Pattyn23-May-09 11:25
sitebuilderLuc Pattyn23-May-09 11:25 
GeneralRe: Displaying the output of a console application in a windows form. Pin
neoflame23-May-09 11:32
neoflame23-May-09 11:32 
GeneralRe: Displaying the output of a console application in a windows form. Pin
Luc Pattyn23-May-09 11:37
sitebuilderLuc Pattyn23-May-09 11:37 
You'd better show real code, there must be a small mistake somewhere, and without the actual code people can't help you locate it.

Anyway, the below code works for me:
public void log(string s) {
    lb.Items.Add(s);
    lb.TopIndex=lb.Items.Count-1;
}

private void button1_Click(object sender, EventArgs e) {
    p=new Process();
    p.EnableRaisingEvents = true;
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.Domain = "";
    p.StartInfo.ErrorDialog = true;
    p.StartInfo.LoadUserProfile = false;
    p.StartInfo.Password = null;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.StandardErrorEncoding = null;
    p.StartInfo.StandardOutputEncoding = null;
    p.StartInfo.UserName = "";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.FileName = "ipconfig";
    p.SynchronizingObject = this;
    p.Exited+=p_Exited;
    p.ErrorDataReceived+=p_ErrorDataReceived;
    p.OutputDataReceived+=p_OutputDataReceived;
    p.Start();
    p.BeginOutputReadLine();
    p.BeginErrorReadLine();
}
private void p_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e) {
    if (!String.IsNullOrEmpty(e.Data)) log("OUT: "+e.Data);
}

private void p_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e) {
    if (!String.IsNullOrEmpty(e.Data)) log("ERR: "+e.Data);
}

private void p_Exited(object sender, EventArgs e) {
     log("END: Application Finished");
     p.CancelOutputRead();
     p.CancelErrorRead();
}


Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

GeneralRe: Displaying the output of a console application in a windows form. Pin
neoflame23-May-09 12:44
neoflame23-May-09 12:44 
GeneralRe: Displaying the output of a console application in a windows form. Pin
Luc Pattyn23-May-09 12:51
sitebuilderLuc Pattyn23-May-09 12:51 
QuestionDataGridView Cursor Move. Pin
Ashwani Dhiman23-May-09 2:38
Ashwani Dhiman23-May-09 2:38 
AnswerRe: DataGridView Cursor Move. Pin
Eddy Vluggen23-May-09 3:42
professionalEddy Vluggen23-May-09 3:42 
QuestionCrystal report print by coding Pin
KIDYA23-May-09 2:12
KIDYA23-May-09 2:12 
AnswerRe: Crystal report print by coding Pin
_Maxxx_24-May-09 16:59
professional_Maxxx_24-May-09 16:59 
QuestionHow to move a drawn ball by Threading? Pin
pcsience23-May-09 0:01
pcsience23-May-09 0:01 
AnswerRe: How to move a drawn ball by Threading? Pin
Douglas Troy23-May-09 7:03
Douglas Troy23-May-09 7:03 
QuestionPrerequisites Pin
Ashwani Dhiman22-May-09 23:46
Ashwani Dhiman22-May-09 23:46 
QuestionRe: Prerequisites Pin
harold aptroot22-May-09 23:56
harold aptroot22-May-09 23:56 
AnswerRe: Prerequisites Pin
Ashwani Dhiman23-May-09 0:20
Ashwani Dhiman23-May-09 0:20 
QuestionKilling proccesses programatically Pin
Rajdeep.NET is BACK22-May-09 23:17
Rajdeep.NET is BACK22-May-09 23:17 
AnswerRe: Killing proccesses programatically Pin
dan!sh 22-May-09 23:33
professional dan!sh 22-May-09 23:33 
GeneralRe: Killing proccesses programatically Pin
Mycroft Holmes23-May-09 2:02
professionalMycroft Holmes23-May-09 2:02 
AnswerRe: Killing proccesses programatically Pin
0x3c023-May-09 2:37
0x3c023-May-09 2:37 
JokeRe: Killing proccesses programatically Pin
dan!sh 23-May-09 5:32
professional dan!sh 23-May-09 5:32 
GeneralRe: Killing proccesses programatically Pin
Luc Pattyn23-May-09 5:44
sitebuilderLuc Pattyn23-May-09 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.