string result_pro = proc.StandardOutput.ReadToEnd(); this statement gives null string? Anyone know the reason why ?

AnkiIt_wizard5 66 Reputation points
2021-07-01T04:23:41.59+00:00

Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.StartInfo.CreateNoWindow = true;
proc.EnableRaisingEvents = true;
proc.StartInfo.RedirectStandardOutput = true;

                proc.Start();

                string result_pro = proc.StandardOutput.ReadToEnd();
                proc.WaitForExit();
Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Anonymous
    2021-07-01T05:58:11.447+00:00

    Hi @AnkiIt_wizard5 ,

    The Process.StandardOutput Property gets a stream used to read the textual output of the application.

    The issue might relate the procStartInfo, please check the executable file or document which used to start the process, make sure it has the textual output.

    For example:

    Create a Console application and have a textual output:

    namespace Write500Lines  
    {  
        public class Program  
        {  
            public static void Main(string[] args)  
            {  
                Console.WriteLine("Hello World!");  
            }  
        }  
    }  
    

    Then use Process to get the output, the result as below:

    110780-image.png


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Dillion


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.