Console.Write() doesn't show output until a newline

When running an app with `dotnet run`, we are redirecting the standard out and error just to print it out to our standard out and error. However, we are batching the output until we hit a newline, which isn't ideal for console apps.

To fix this, `dotnet run` no longer redirects the standard out and error.

Fix #2777
This commit is contained in:
Eric Erhardt 2016-05-12 10:24:57 -05:00
parent 6482aa0221
commit 6bf59ffde6
7 changed files with 241 additions and 20 deletions

View file

@ -20,16 +20,26 @@ namespace Microsoft.DotNet.Tools.Run
public string Project = null;
public IReadOnlyList<string> Args = null;
private readonly ICommandFactory _commandFactory;
private ProjectContext _context;
private List<string> _args;
private BuildWorkspace _workspace;
public static readonly string[] DefaultFrameworks = new[]
{
FrameworkConstants.FrameworkIdentifiers.NetCoreApp,
FrameworkConstants.FrameworkIdentifiers.NetStandardApp,
};
public RunCommand()
: this(new RunCommandFactory())
{
}
ProjectContext _context;
List<string> _args;
private BuildWorkspace _workspace;
public RunCommand(ICommandFactory commandFactory)
{
_commandFactory = commandFactory;
}
public int Start()
{
@ -166,24 +176,22 @@ namespace Microsoft.DotNet.Tools.Run
}
}
Command command;
ICommand command;
if (outputName.EndsWith(FileNameSuffixes.DotNet.DynamicLib, StringComparison.OrdinalIgnoreCase))
{
// The executable is a ".dll", we need to call it through dotnet.exe
var muxer = new Muxer();
command = Command.Create(muxer.MuxerPath, Enumerable.Concat(
command = _commandFactory.Create(muxer.MuxerPath, Enumerable.Concat(
Enumerable.Concat(new string[] { "exec" }, hostArgs),
Enumerable.Concat(new string[] { outputName }, _args)));
}
else
{
command = Command.Create(outputName, Enumerable.Concat(hostArgs, _args));
command = _commandFactory.Create(outputName, Enumerable.Concat(hostArgs, _args));
}
result = command
.ForwardStdOut()
.ForwardStdErr()
.Execute()
.ExitCode;
@ -198,5 +206,13 @@ namespace Microsoft.DotNet.Tools.Run
var result = command.Execute();
return result.ExitCode;
}
private class RunCommandFactory : ICommandFactory
{
public ICommand Create(string commandName, IEnumerable<string> args, NuGetFramework framework = null, string configuration = "Debug")
{
return Command.Create(commandName, args, framework, configuration);
}
}
}
}