2

Can anyone help me? O(∩_∩)O

Today I meet a question that I want to use a program maybe a player and I need log the data(BCI EEG) from the user.So I try to use the Process Class to Start a ConsoleApplication in an WindowsApplication.

I create a Simple WindowsApplication to have a try my idea. But it not works,I also try to use the Process Class to Start other Application It' Ok.When I Start my own program that is a ConsoleApplication it not works.

 public partial class Form1 : Form
 {
    Process myProcess = new Process();

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        myProcess.StartInfo.UseShellExecute = false;
        // You can start any process, HelloWorld is a do-nothing example.
        myProcess.StartInfo.FileName = "D:\\EEG\\Emotiv Xavier TestBench v3.0.0.41\\EmotivXavierTestBench.exe";
        myProcess.StartInfo.CreateNoWindow = true;
        myProcess.Start();

        //System.Console.WriteLine("Hello World!");
        //MessageBox.Show("button1.Click was raised.");
    }

This TestBench program can open .But why the program I create doesn't work? D:\temp\EmotivConnection\Debug\EmotivConnection.exe

  • What is "*it not works*" exactly? You have an *exception thrown*, it *doesn't compile*, you see *no output*, the *actual behaviour* is not an expected one? – Dmitry Bychenko Mar 11 '16 at 07:19
  • Is the return value true or false at `myProcess.Start();`? What about a Try - catch block, do you get an exception? – Nitro.de Mar 11 '16 at 07:34

2 Answers2

1

So you've run the application, but don't allow to create any console window by

  myProcess.StartInfo.CreateNoWindow = true;

And so you see nothing (the application runs however). Probably, you want to re-direct the output (and show it in, say, MyTextBox instead of console window)

private void button1_Click(object sender, EventArgs e) {
  // Process is IDisposable, so wrap it into using
  using (Process myProcess = new Process()) {
    myProcess.StartInfo.UseShellExecute = false;
    // You can start any process, HelloWorld is a do-nothing example.
    myProcess.StartInfo.FileName = 
      //"cmd.exe"; // <- standard test 
      "D:\\EEG\\Emotiv Xavier TestBench v3.0.0.41\\EmotivXavierTestBench.exe";
    myProcess.StartInfo.CreateNoWindow = true;

    // Crucial: we want to see the output in MyTextBox, 
    // not in the standard console (which is hidden by "CreateNoWindow = true")
    myProcess.StartInfo.RedirectStandardOutput = true;
    // You may want this as well
    //myProcess.StartInfo.RedirectStandardError = true;

    myProcess.Start();

    myProcess.WaitForExit();

    // Do not forget to put MyTextBox on the form 
    // Read the output ("Hello World") in the MyTextBox    
    MyTextBox.Text = myProcess.StandardOutput.ReadToEnd();
  }
}
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
0

You are calling

myProcess.StartInfo.CreateNoWindow = true;

have you checked, if your task manager contains your program?

I assume it is actually running but in the same window as your current app.

About CreateNoWindow: "true if the process should be started without creating a new window to contain it; otherwise, false. The default is false."

Source: MSDN

This could help you aswell:

proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

.NET - WindowStyle = hidden vs. CreateNoWindow = true?

Community
  • 1
  • 1
Mafii
  • 7,227
  • 1
  • 35
  • 55
  • Please consider accepting my answer if it helped you to solve the problem. please look at the link i've added in the end about `ProcessWindowStyle.Hidden;` – Mafii Mar 11 '16 at 08:11
  • If you're really curious about c# and wanna learn more in depth, i recommend [this websites](http://ericlippert.com/) part about c#, because the writer (eric lippert) has been working on the c#-compiler for a few years, so he knows his shit. – Mafii Mar 11 '16 at 08:36