nig*_*her 4 c# c++ command-line-interface
我编写了一个C++程序(从命令行执行),工作正常.现在我需要将它用于我的C#应用程序.也就是说,我希望我的C++程序的输出可以在我调用C#应用程序时使用.
可能吗?如果是这样,怎么样?
任何链接或帮助将不胜感激.
您可以使用System.Diagnostics.Process启动C++程序并将其输出重定向到流以在C#应用程序中使用.在信息这个问题的详细细节:
string command = "arg1 arg2 arg3"; // command line args
string exec = "filename.exe"; // executable name
string retMessage = String.Empty;
ProcessStartInfo startInfo = new ProcessStartInfo();
Process p = new Process();
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;
startInfo.Arguments = command;
startInfo.FileName = exec;
p.StartInfo = startInfo;
p.Start();
using (StreamReader output = p.StandardOutput)
{
retMessage = output.ReadToEnd();
}
p.WaitForExit();
return retMessage;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
851 次 |
| 最近记录: |