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 8505219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:15:25+00:00 2026-06-11T02:15:25+00:00

I am using code like this: System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo =

  • 0

I am using code like this:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C SomeEXE inputfile.txt";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;

process.StartInfo = startInfo;
process.Start();

// Now use streams to capture the output
StreamReader outputReader = process.StandardOutput;

process.WaitForExit();

String line = outputReader.ReadToEnd();

This works fine. However, the issued command (SomeEXE) results in another command prompt being opened which contains the actual results and awaits a carriage return to be closed. Is it possible to obtain this output and issue a carriage return? Thanks.

  • 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-06-11T02:15:26+00:00Added an answer on June 11, 2026 at 2:15 am

    Launching SomeEXE directly

    If you launch SomeEXE directly, rather than via a new command interpreter, your existing code to obtain the output by redirecting stdout to outputReader will work. To do that, change your code as follows:

    startInfo.FileName = "SomeEXE";
    startInfo.Arguments = "inputfile.txt";
    

    You can redirect stdin to your own stream as well so that you can issue the carriage return:

    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardinput.aspx

    Key points:

    myProcess.StartInfo.RedirectStandardInput = true;
    StreamWriter myStreamWriter = myProcess.StandardInput;
    

    Write Environment.NewLine to myStreamWriter.

    However, since you are not doing that, you are capturing the console of the command interpreter.

    If you control SomeEXE’s code

    If you have control over SomeEXE, you can instruct it to attach to its parent’s console:

    http://www.csharp411.com/console-output-from-winforms-application/

    Note that the MSDN examples show very poor exception handling. They fail to close the streams in the example if an exception is thrown. The easiest way to dispose of the streams is to wrap them in using statements.

    If SomeEXE spawns a child process

    If you have no control over SomeEXE’s code, and SomeEXE is spawning a child process, the task of grabbing stdin/stdout from the grandchild console is harder. However, it can be done.

    You need to obtain the process ID of the actual console window in question.

    Then, you can use the Win32 API AttachConsole to attach the grandchild process’ console to your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using dotnet 2.0. I currently have code like this : DataView dv = new
My Code goes like this: using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) { string resultString
I have problem installing simple Windows Service, my code looks like this: using System;
The program’s code is like below: using System.Diagnostics; class Test { static void Main()
I am creating an archive on Android using the code like this: OutputStream os
I am using nhibernate and i have code like this in the mapping area:
In many places in our application we have code like this: using(RAPI rapi =
When using XML serialization in C#, I use code like this: public MyObject LoadData()
I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor
I am using JQM 1.1.0 and Cordova 1.5.0. I have code like this <!DOCTYPE

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.