[MonoDevelop] Process with Mono
guybrush.d
thera at interfree.it
Sun Nov 14 17:49:38 EST 2010
Hi everybody,
Let me first excuse if my question has already been answered, but i didn't
find it.
OK My question is I'm trying to develop a gui application (GTK#) for
Slackware,
it will be a gui for slapt-get and more, i know that there are already other
gui for slapt-get
but mine will be with more functions. My problem is to read the standard
output from console
when i launch slapt-get, i've already been able to read it in asynchronous
mode, pratically
i call the command with "Process.Start" method and after a while i'm able to
display the std out
to a text view. What i'm not able to do is to display the std out while
slapt-get is working. I've tried
the treads method but i haven't been able to make it work, i have a couple
of class on windows
that fits perfectly my needs, i already used it for other apps, but they
works with windows forms
and i'm developing an application for gtk so the classes used are not
available! I've googled everywhere,
i've even tried to use the vte terminal, but i don't understand how to
retrieve the output! Can anybody suggest me
how to accomplish this? Here two pieces of code i used:
This is the simple method i used it starts the program, and after the
command has been
executed, it shows me the result in the text view.
protected virtual void StartProcess()
{
sortProcess.StartInfo.UseShellExecute = false;
// I redirect the standard output
sortProcess.StartInfo.RedirectStandardOutput = true;
sortProcess.StartInfo.FileName = @"/usr/sbin/slapt-get";
sortProcess.StartInfo.Arguments = " --list"; //--list";
sortProcess.StartInfo.WorkingDirectory = @".";
sortProcess.Start();
// I read the output to a string
stdOutput = sortProcess.StandardOutput.ReadToEnd();
// and then load the textview
textview1.Buffer.Text = stdOutput;
sortProcess.WaitForExit ();
}
Second Method i tried to used threads, but the result is almost the same:
public void FirstUnsyncThreads ()
{
// Crea due threads. The ThreadStart delegate is points to
// the method being run in a new thread.
Thread firstRunner = new Thread (new ThreadStart (this.firstRun));
Thread secondRunner = new Thread (new ThreadStart (this.secondRun));
// Starting our two threads. Thread.Sleep(10) gives the first Thread
// 10 miliseconds more time.
firstRunner.Start ();
Thread.Sleep (10);
secondRunner.Start ();
}
// This method is being excecuted on the first thread.
public void firstRun ()
{
sortProcess.StartInfo.UseShellExecute = false;
// we need to redirect the standard output so we read it
// internally in out program
sortProcess.StartInfo.RedirectStandardOutput = true;
sortProcess.StartInfo.FileName = @"/usr/sbin/slapt-get";
sortProcess.StartInfo.Arguments = " --list"; //--list";
sortProcess.StartInfo.WorkingDirectory = @".";
sortProcess.Start();
// read the output to a string
stdOutput = sortProcess.BeginOutputReadLine.ToString();
sortProcess.WaitForExit ();
Thread.Sleep (100);
}
// This method is being excecuted on the second thread.
public void secondRun ()
{
// finally output the string
textview1.Buffer.Text = stdOutput;
}
Ok guys that's all i'm in your hands, if i don't understand how make this
work
my app will be almost useless, this code will also make a progress bar
increment
but i need to get the std output in synchro else i won't work!!!Please HELP!
PS.: Sorry for my english, if i made some mystake i'm just italian, CIAO.
--
View this message in context: http://mono.1490590.n4.nabble.com/Process-with-Mono-tp3042268p3042268.html
Sent from the Mono - MonoDevelop IDE mailing list archive at Nabble.com.
More information about the Monodevelop-list
mailing list