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

  • Home
  • SEARCH
  • 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 8234209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:24:06+00:00 2026-06-07T18:24:06+00:00

Possible Duplicate: Command prompt output being read as empty string I have a command

  • 0

Possible Duplicate:
Command prompt output being read as empty string

I have a command line program which must be executed at least once before my code can do it’s groovy thang. So I use Process to run it. This appears to work.

My problem lies in the fact that I’d like to be able to see what the program says as it completes. In some situations it may return an error, which would require user intervention before proceeding. On paper, this seems trivial. Sadly, my code (below) does not seem to work:

Process p = new Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = String.Format("/C adb forward tcp:{0} tcp:5574",port.ToString());
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
p.StartInfo = startInfo;
p.Start();
string adbResponse = p.StandardOutput.ReadToEnd();
p.WaitForExit();
if (adbResponse.Contains("error"))
{
    // Device not connected - complain loudly
}

When I try doing this on a CMD window of my own creation, I am able to reliably induce a response containing the word error. (Specifically by unplugging something.) Under the same conditions however, the adbResponse string remains empty. What am I missing?

  • 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-07T18:24:08+00:00Added an answer on June 7, 2026 at 6:24 pm

    Console-attached processes have two different output streams. You are trapping StandardOutput but you probably want to be catching StandardError. See this question for a complete explanation (and code to safely capture both without deadlocking):

    Command prompt output being read as empty string

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

Sidebar

Related Questions

Possible Duplicate: How can I pass command-line arguments to a Perl program? I have
Possible Duplicate: Windows Program: How to snoop on command line arguments? I am working
Possible Duplicate: Output of command in Bash script to Drop-down box? I have an
Possible Duplicate: Can I run from command line program created by Eclipse? I am
Possible Duplicate: Unix command-line JSON parser? If I have a config file in JSON
Possible Duplicate: Running a command from Ruby displaying and capturing the output I have
Possible Duplicate: What's the best way to grab/parse command line arguments passed to a
Possible Duplicate: Deflate command line tool Yes, I know I can use PHP itself
Possible Duplicate: Android Unknown Command 'crunch' I have been using eclipse just fine but
Possible Duplicate: Build Eclipse Java Project from Command Line I want to compile my

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.