简体   繁体   中英

Trouble executing a C++ console application from a C# GUI

I am trying to execute a console application developed in C++, although in C# when I use a method such as:

private void StartProcess()
{
Process.Start("consoleapp.exe");
}

It does not appear or even seem to execute, no exceptions thrown etc.

Is there a better way to do this?

Is consoleapp.exe in the same directory as your c# executable or in the path?

There is a good description of how to do this in the following article:

How To: Execute command line in C#, get STD OUT results

Yes, try doing it like this,

using System;
using System.Diagnostics;

class ProcessStart{
    static void Main(string[] args){

        Process sample = new Process();

        sample.StartInfo.FileName   = "sample.exe";
        sample.Start();
    }
}

the key code is in the main function, just make sure the exe is in the same directory, and include the

using System.Diagnostics; 

at the top.

this code works for me and seems the most correct way. hope i helped.

    Process sample = new Process();

    sample.StartInfo.FileName   = "sample.exe";
    sample.Start();

just change the Process sample to w/e you want, so sample can be w/e you want.

you may also pass arguments to the exe using this.

sample.StartInfo.Arguments = "sample argument";

just put this before the starting the exe part.

hope i helped:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM