0

I have a cpp console app that returns some random strings. How to get its output string?

Below what I have tried to call that cpp console app, but I don't have any idea to get its output string?

        var processInfo = new ProcessStartInfo();
        processInfo.FileName = "/tmp/mycpp.exe ";
        processInfo.Arguments = _jpg;
        processInfo.CreateNoWindow = true;
        processInfo.UseShellExecute = false;

        using (var process = new Process())
        {
            process.StartInfo = processInfo;
            process.Start();
            process.WaitForExit();


        }

and the output string looks like below:

[root@demo car-make-model-classifier-yolo3-cpp]# ./mycpp helloworld
------------------------------------------------
value1: helloworld1
value2: helloworld2
------------------------------------------------

------------------------------------------------
value1: helloworld11
value2: helloworld22
------------------------------------------------
Renan Araújo
  • 3,533
  • 11
  • 39
  • 49
Don2
  • 313
  • 3
  • 12
  • Use [`ProcessStartInfo.RedirectStandardOut`](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=netcore-3.1). I'm sure there are a lot of answers on SO, but I admit it's not so easy to find them – René Vogt Jun 10 '20 at 12:54
  • 2
    Does this answer your question? [Process.start: how to get the output?](https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output) – MindSwipe Jun 10 '20 at 12:55
  • `Process.ExitCode` if that's what you mean. Processes have no output values, they write to the output stream. If you want that output you need to redirect the output stream – Panagiotis Kanavos Jun 10 '20 at 12:55
  • I tried ReadLine but it returns empty – Don2 Jun 10 '20 at 15:41

0 Answers0