Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

System.Diagnostics.Process redirect causes IOException only in Unity .NET 4.X

Discussion in '2018.2 Beta' started by LouisHong, Jun 23, 2018.

  1. LouisHong

    LouisHong

    Joined:
    Nov 11, 2014
    Posts:
    69
    Attached is a recreation of the bug. This error only occurs when Unity is set to .NET 4.X and runs fine in .NET 3.5

    To trigger the bug press the menu item in the top menu.



    Expected Output In Debug Console:
    Hello World

    Actual Output:
    IOException


    Code (CSharp):
    1. using System.Diagnostics;
    2. using UnityEditor;
    3. using UnityEngine;
    4. using Debug = UnityEngine.Debug;
    5.  
    6. public static class Program
    7. {
    8.     [MenuItem("BUG REPORT HERE/Reproduce Bug")]
    9.     public static void Bug()
    10.     {
    11.         var _process = new Process {
    12.             StartInfo = {
    13.                 FileName = "echo /c",
    14.                 Arguments = "hello world",
    15.                 WorkingDirectory = ".",
    16.                 CreateNoWindow = true,
    17.                 RedirectStandardOutput = true,
    18.                 RedirectStandardError = true,
    19.                 UseShellExecute = false,
    20.             }
    21.         };
    22.         _process.Start();
    23.         _process.WaitForExit();
    24.         Debug.Log(_process.StandardOutput.ReadToEnd()); // IOException      
    25.     }
    26. }
    27.  
     

    Attached Files:

    LeonhardP likes this.
  2. yakswa

    yakswa

    Joined:
    Feb 27, 2015
    Posts:
    1
    same error on process.StandardError.ReadLine();
     
  3. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,135
    Hi,
    Thanks for reporting that issue! We have fixed it in our main repository and will backport the fix to 2018.2 asap. If all goes well it should be resolved in the next release of 2018.2.