Just a little background for you guys - Ive dabbled around in C# for awhile now and have started writing a few apps as side-projects, or things Ive wanted but havent been able to find. With that being said, Im not the best coder out there, and Im well aware of that. However, Im more than willing to learn, and Im doing everything I can to figure these things out on my own.

Now, on to the problem at hand.

Im trying to create a GUI for a CLI (command-line interface) program called iphone_tunnel. Long story short, the application hooks an Apple DLL and "tunnels" any TCP port over the iPhone's USB cable. This is incredibly handy for copying files or for VNC, as you dont need a (slow, vs hardwired) wireless connection.

The syntax of the program is this:
"iphone_tunnel [iPhone Port] [Local Port]"

For example, if I wanted to SSH to the device, I would use:
"iphone_tunnel 22 22"

And then use 127.0.0.1 / localhost as the address to connect to.



Since Im trying to teach myself C#, I decided I wanted to create a pretty little GUI for the console app, and came up with this:


This is the code I have so far (Im using Visual C# 2008 Express w/ .NET 3.5 SP1):
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace iPhone_Tunnel_GUI
{
    public partial class Form1 : Form
    {
        string exeFile = @"iphone_tunnel.exe";
        Process p = new Process();

        public Form1()
        {
            InitializeComponent();
        }

        private void startButton_Click(object sender, EventArgs e)
        {
            if (statusLabel.Text != "Started")
            {
                if (!File.Exists(exeFile))
                {
                    MessageBox.Show("Please make sure iphone_tunnel.exe is in the same directory as this GUI.");
                }
                p.StartInfo.FileName = exeFile;
                p.StartInfo.Arguments = "22 22";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                //p.StartInfo.CreateNoWindow = true;
                //p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
                p.Start();
                outputBox.Text = p.StandardOutput.ReadToEnd();
                //p.WaitForExit();
                statusLabel.ForeColor = Color.Green;
                statusLabel.Text = "Started";
            }
        }

        private void stopButton_Click(object sender, EventArgs e)
        {
            if (statusLabel.Text != "Stopped")
            {
                p.Close();
                statusLabel.ForeColor = Color.Red;
                statusLabel.Text = "Stopped";
            }
        }
    }
}
Some parts may be redundant or unnecessary, but Id like to get a working version first, and clean it up and tweak later. For example, Ive set the arguments for the program to always be "22 22" so that I can get the app loading/logging part working, before delving into something else. What I plan on having is a predefined list of common ports, and a radio box that lets you fill in custom ports, with different ports for the iPhone and the local port.

For example - I run a VNC server on my laptop, but I also want to VNC into the phone - so I start the program with the arguments "5900 5500" so that I can connect to port 5500 on my computer, and that is translated to port 5900 on the phone.

Now, for the problem:
When I press Start, a console window opens with a flashing cursor (this is iphone_tunnel.exe opening). The program is running, because I can SSH into the device; but the text that normally shows up in a console window doesnt show up in the window that pops up. Aswell, the GUI freezes up solid until I CTRL+C, or close the console window that pops up.

I want to click Start, have the log of the application show up in the text box, and keep the app responsive, so I can then hit Stop when I want to.

Im pretty sure the code is stopping at this line:
"outputBox.Text = p.StandardOutput.ReadToEnd();"
because once I CTRL+C, only then does the label change to "Started".

Where should I begin? Thanks!