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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:50:12+00:00 2026-05-15T06:50:12+00:00

Could you please explain why the shell redirection doesn’t work with System.Diagnostics.Process class? I

  • 0

Could you please explain why the shell redirection doesn’t work with System.Diagnostics.Process class? I am trying to redirect the output streams to file with the following snippet:

Process p = new Process();
p.StartInfo = new ProcessStartInfo();
p.StartInfo.FileName = "java.exe";
p.StartInfo.Arguments = @"> c:\Temp\test.log 2>&1";
p.StartInfo.UseShellExecute = true;
p.Start();

The similar code works without problems with Python.
Reading the output streams programmatically doesn’t seem a preferable solution in my case because there will be a bunch of processes launched by my application.

  • 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-15T06:50:14+00:00Added an answer on May 15, 2026 at 6:50 am

    You cannot do the redirection because there is no shell directly involved. You could run a cmd.exe session, but the proper way to do it is using the RedirectStandardOutput/Error properties. There is no problem when having many processes. This is a class I use for this.

        class HandleExecutable {
            private DataReceivedEventHandler outputHandler;
    
            public DataReceivedEventHandler OutputHandler
            {
                set { outputHandler = value; }
            }
            private DataReceivedEventHandler errorHandler;
    
            public DataReceivedEventHandler ErrorHandler
            {
                set { errorHandler = value; }
            }
    
            public void callExecutable(string executable, string args)
            {
                string commandLine = executable;
                string args = args;
                ProcessStartInfo psi = new ProcessStartInfo(commandLine);
                psi.UseShellExecute = false;
                psi.LoadUserProfile = false;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError = true;
                psi.WindowStyle = ProcessWindowStyle.Minimized;
                psi.CreateNoWindow = true;
                psi.Arguments = args;
                p = new Process();
                p.StartInfo = psi;
                try
                {
                    p.Start();
                    p.BeginOutputReadLine();
                    p.BeginErrorReadLine();
                    if (outputHandler != null) p.OutputDataReceived += outputHandler;
                    if (errorHandler != null) p.ErrorDataReceived += errorHandler;
                    p.WaitForExit();
                    p.Close();
                    p.Dispose();
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                }
            }
        }
    
        //On another class
        void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            //HANDLE STDERR
            if (e.Data != null && !e.Data.Equals(""))
            {
                 if (!e.Data.Contains("Something")) {
                 }
            }
        }
    
        void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            //HANDLE STDOUT
            if (e.Data != null && !e.Data.Equals(""))
            {
            }
        }
    
        HandleExecutable he = new HandleExecutable();
        he.OutputHandler = p_OutputDataReceived;
        he.ErrorHandler = p_ErrorDataReceived;
        he.callExecutable(@"C:\java.exe","-cp foo ClassName");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This might be of some use to you. May 16, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer Seems like homework, if so best to tag it as… May 16, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer A common mistake that people make when trying to design… May 16, 2026 at 10:06 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Can someone please explain where GetModuleCatalog (Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.GetModuleCatalog()) is called in the Prism shell? I
Could you please explain the following two questions about Visual Web Developer 2008? 1)
Please, could someone explain me why "make-array" has no effect on plant1? (LET (plant1)
I was just wondering if anyone could explain to me how a price comparison
Could you please tell me what the equivalent BASH code for the following C++
Could anyone please tell me what the web developers can do with cloud computing,
Everything is in the title, I doesn't understand what the statement below does: #import
I'm having trouble installing Django, even if I follow the instructions here: http://www.djangobook.com/en/2.0/chapter02/ Could
I would like to know exactly how the Is command works in Linux and
This is a very basic concept, but something I have never been able to

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.