开发者

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

开发者 https://www.devze.com 2023-03-20 23:07 出处:网络
I am trying to execute a console application developed in C++, although in C# when I use a method such as:

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 开发者_如何学Pythonexecute, no exceptions thrown etc.

Is there a better way to do this?


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 :)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消