Mono C# gtk# GUI Gnome-terminal


New member
Jun 11, 2019
Programming Experience
I'm trying do an Gui terminal on MonoDevelop using Gtk project and c# (csharp), but I cant find a sample that works on mono so i start building my own. this is my actual code:

my code:
using System;
using System.Diagnostics;

using Gtk;

public partial class MainWindow : Gtk.Window
    public MainWindow() : base(Gtk.WindowType.Toplevel)

    protected void OnDeleteEvent(object sender, DeleteEventArgs a)
        a.RetVal = true;

    protected void OnEntry3KeyReleaseEvent(object o, KeyReleaseEventArgs args)

    protected void OnButton1Clicked(object sender, EventArgs e)
        //ExecuteCommand("gnome-terminal -x bash -ic 'cd $HOME; ls; bash'");

        //textview1.Buffer.Text = textview1.Buffer.Text + "\r\n" +     entry3.Text.ToString();
        entry3.Text = "";


    protected void ExecuteCommand(string command)
        Process proc = new System.Diagnostics.Process();
        proc.StartInfo.FileName = "gnome-terminal";
        //proc.StartInfo.Arguments = "-c \" " + command + " \"";
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = true;

        while (!proc.StandardOutput.EndOfStream)
            textview1.Buffer.Text = proc.StandardOutput.ReadToEnd();

The Idea is have a gui terminal with text input and output.
Can you help?
Do you have a particular problem that you are trying fix?
Do you have a particular problem that you are trying fix?

Hi Skydiver,
Thanks for reply.
Yes I have, the code I have does not work as I expected, ou can see here on this video (I record it now to post)
there is an new window flashing but I got no output on my textview, After record this video I try open firefox and it opened but still, no output on my textview.

The Idea is to write the command on the little text box on the bottom click send and get the output on the big textview box.
I will need to control input and process outputs to and from the linux terminal, I will use a gui to manage some commands and do stuff based on outputs.

Something like this:
Send command and read output
Process output
send reply command based on last output and read new output
and go on......

I dont know if it is important but I Install mono using Mono repository on monodevelop/downloads web site +-1 day ago.

Any suggestion, tutorial, code, idea?
Why are you trying to pass the `ls` command to gnome-terminal as a parameter? Why not just execute it directly?
Good point!!! :unsure:

I got thinking proc.StartInfo.FileName it's the terminal I want to use and all command must be in proc.StartInfo.Arguments

I will try!!!
Why are you trying to pass the `ls` command to gnome-terminal as a parameter? Why not just execute it directly?

It worked very well, I thinks I need to refine my code and/or search for a better sample....

Now When I try run "cd ~/" or cd / the window just close with out errors

Do you know some sample code I can use in here?
or some online project where i can strip code form it?
or you now from the top or your head why it close?
or something else?

For `cd` as well as various commands that actually change the state of the shell, you don't actually want to send those to OS to be executed. Instead those you want to translate yourself and call the the appropriate .NET Framework API. For example for `cd`, you'll want to set Environment.CurrentDirectory.

If you search around online, there are a bunch of folks going through their Operating Systems assignments where they have to create their own shell. That is essentially what you need to do here. The only differences between their assignments and what you are trying to do are:
  • You are using C# while they are using C.
  • You are using the .NET Framework while they are using the C library and the OS APIs.
  • You are using the Gtk library to interact with GUI elements while they are calling the C library (and/or the OS) to interact with the console APIs.
Top Bottom