I wrote a C ++ program (which runs from the command line) that works fine. Now I need to use it for my C # application. That is, I would like the output of my C ++ program to be used in my C # application whenever it is called.
Is it possible? If so, how?
Any links or help would be appreciated.
You can use System.Diagnostics.Processto run your C ++ program and redirect output to a stream for use in your C # application. The information in this question details the specifics:
System.Diagnostics.Process
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;
++- DLL pinvoke ++ #.
: DLL Win32 # P/Invoke
- Process .Net. Process, DLL ++-; ++ EXE #.
++ # .
, .
# ++:
try { Process p = StartProcess(ExecutableFileName); p.Start(); p.WaitForExit(); } catch { Log("The program failed to execute."); }
++ #.
, ++: http://www.cplusplus.com/doc/tutorial/files/
, #: http://msdn.microsoft.com/en-us/library/ezwyzy7b.aspx
, OP , , | ? , , "" ", ". "" ++, . "" #, :
C:\>myCpluplus.exe | myCsharp.exe
Console.In myCsharp.exe.
Source: https://habr.com/ru/post/1787879/More articles:NHibernate WARNING and data is not saved - nhibernateopen source .NET based user management system? - .netPHP Image quality issue during rotation and merging - phpIs there a way to use BigInteger to iterate? - javaCannot open VSVim project - visual-studio-2010How to run an elevated privilege application in Vista + using Java / JNA to run UAC - javaHow to change text alignment in QTabWidget in C ++? - c ++How to make this code simpler, more understandable and more lazy? - common-lispперечислять ключи в System.Collections.Generic.Dictionary <строка, строкa> - dictionaryQt - How to set text on top of QLabel Image - qtAll Articles