Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 800933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:21:58+00:00 2026-05-14T23:21:58+00:00

Ok this is not duplicate of Alternative to Process.Start() because my question is something

  • 0

Ok this is not duplicate of “Alternative to Process.Start()” because my question is something different here.

I need to run a process and wait till execution of process and get the output of console.

There is way to set RedirectStandardOutput and RedirectStandardError to true, however this does not function well on some machines, (where .NET SDK is not installed), only .NET runtime is installed, now it works on some machines and doesnt work on some machines so we dont know where is the problem.

I have following code,

        ProcessStartInfo info = new ProcessStartInfo("myapp.exe", cmd);
        info.CreateNoWindow = true;
        info.UseShellExecute = false;
        info.RedirectStandardError = true;
        info.RedirectStandardOutput = true;
        Process p =  Process.Start(info);
        p.WaitForExit();
        Trace.WriteLine(p.StandardOutput.ReadToEnd());
        Trace.WriteLine(p.StandardError.ReadToEnd());

On some machines, this will hang forever on p.WaitForExit(), and one some machine it works correctly, the behaviour is so random and there is no clue.

Now if I can get a real good workaround for this using pinvoke, I will be very happy.

myapp.exe is nothing but writing 10 hello world statements on screen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:21:59+00:00Added an answer on May 14, 2026 at 11:21 pm

    Ok I got this answer from somewhere…

        using System.Diagnostics;
        using System.Threading;
    
        ProcessStartInfo info = new ProcessStartInfo("myapp.exe", cmd); 
        info.CreateNoWindow = true; 
        info.UseShellExecute = false; 
        info.RedirectStandardError = true; 
        info.RedirectStandardOutput = true; 
        Process p =  new Process();
        p.StartInfo = info; 
        p.BeginOutputReadLine();
        p.BeginErrorReadLine();
    
        AutoResetEvent wait = new AutoResetEvent(false);
    
        p.Exited += (s,e)=>{
            wait.Set();
        }
        p.Start();
        wait.WaitOne();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is NOT a duplicate question, and the problem is driving me crazy. I
PreNote: This is not a duplicate. I've checked several questions and mine is different
I hope this question is not a duplicate but I didn't find anything equivalent
Follow-up question to this question : (note that this is not a duplicate, I'm
First off, this is NOT a duplicate of: Turn a C string with NULL
Possible Duplicate: Comparing Strings in Cocoa Why is this code not recognising the NSString
Possible Duplicate: Why does this intentionally incorrect use of strcpy not fail horribly? Below
I am sorry if this is a duplicate but I was not able to
My apologies if this is a duplicate; I may not know the proper terms
Read on before you say this is a duplicate, it's not. (as far as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.