Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. .NET Process does not get along with .NET console

.NET Process does not get along with .NET console

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharptestingbeta-testing
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    puromtec1
    wrote on last edited by
    #1

    So I am not sure if this is my "worst practices" or MS'. If you start a process (console app) which makes a call to Console.WindowWidth from C# (3.5) Process object, it crashes. I guess, I'm removing my fancy console screen formatting--for automated system testing, at least.

    System.Diagnostics.Process p = new System.Diagnostics.Process();

            p.StartInfo.FileName = "DummyTest.exe";            
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();   //<-------<< causes System.IOException because of Console.WindowWidth
    

    namespace DummyTest
    {
    class Program
    {
    static void Main(string[] args)
    {

            Console.WriteLine("Hello world! My window is this wide:");
            Console.WriteLine(Console.WindowWidth.ToString());
        }
     }
    

    }

    M M 2 Replies Last reply
    0
    • P puromtec1

      So I am not sure if this is my "worst practices" or MS'. If you start a process (console app) which makes a call to Console.WindowWidth from C# (3.5) Process object, it crashes. I guess, I'm removing my fancy console screen formatting--for automated system testing, at least.

      System.Diagnostics.Process p = new System.Diagnostics.Process();

              p.StartInfo.FileName = "DummyTest.exe";            
              p.StartInfo.UseShellExecute = false;
              p.StartInfo.RedirectStandardInput = true;
              p.StartInfo.RedirectStandardOutput = true;
              p.Start();   //<-------<< causes System.IOException because of Console.WindowWidth
      

      namespace DummyTest
      {
      class Program
      {
      static void Main(string[] args)
      {

              Console.WriteLine("Hello world! My window is this wide:");
              Console.WriteLine(Console.WindowWidth.ToString());
          }
       }
      

      }

      M Offline
      M Offline
      Mark Hurd
      wrote on last edited by
      #2

      That makes sense because you're piping its IO (.RedirectStandardXxx = true), so it is not connected to the console, just your starting program. I have confirmed this by replicating your exception (in VB.NET) and then only changing to

      .RedirectStandardOutput = False

      and there is then no error, but it may of course not be the functionality you need.

      Regards, Mark Hurd, B.Sc.(Ma.) (Hons.)

      P 1 Reply Last reply
      0
      • P puromtec1

        So I am not sure if this is my "worst practices" or MS'. If you start a process (console app) which makes a call to Console.WindowWidth from C# (3.5) Process object, it crashes. I guess, I'm removing my fancy console screen formatting--for automated system testing, at least.

        System.Diagnostics.Process p = new System.Diagnostics.Process();

                p.StartInfo.FileName = "DummyTest.exe";            
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.Start();   //<-------<< causes System.IOException because of Console.WindowWidth
        

        namespace DummyTest
        {
        class Program
        {
        static void Main(string[] args)
        {

                Console.WriteLine("Hello world! My window is this wide:");
                Console.WriteLine(Console.WindowWidth.ToString());
            }
         }
        

        }

        M Offline
        M Offline
        Mirko1980
        wrote on last edited by
        #3

        Console has a LargestWindowWidth property, you could try to check what value has when RedirectStandardOutput is true.

        1 Reply Last reply
        0
        • M Mark Hurd

          That makes sense because you're piping its IO (.RedirectStandardXxx = true), so it is not connected to the console, just your starting program. I have confirmed this by replicating your exception (in VB.NET) and then only changing to

          .RedirectStandardOutput = False

          and there is then no error, but it may of course not be the functionality you need.

          Regards, Mark Hurd, B.Sc.(Ma.) (Hons.)

          P Offline
          P Offline
          puromtec1
          wrote on last edited by
          #4

          Ahh... and it is by design. A little further reading indicates that when redirecting io the underlying io and error streams Console object has NOTHING to do with the console screen that might be displayed albeit blank. This was lost on me initially.

          Console class members that work normally when the underlying stream is directed to a console might throw an exception if the stream is redirected, for example, to a file. Consequently, program your application to catch System.IO..::.IOException if you redirect a standard stream.

          http://msdn.microsoft.com/en-us/library/system.console.aspx[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups