in src/Cli/func/Actions/HostActions/StartHostAction.cs [590:651]
private void StartHostAsChildProcess(bool shouldStartNet8ChildProcess)
{
if (VerboseLogging == true)
{
ColoredConsole.WriteLine(VerboseColor($"Starting child process for {(shouldStartNet8ChildProcess ? DotnetConstants.InProc8HostRuntime : DotnetConstants.InProc6HostRuntime)} model host."));
}
var commandLineArguments = string.Join(" ", Environment.GetCommandLineArgs().Skip(1));
var tcs = new TaskCompletionSource();
var funcExecutablePath = GetInProcExecutablePath(isNet8: shouldStartNet8ChildProcess);
EnsureFuncExecutablePresent(funcExecutablePath, shouldStartNet8ChildProcess);
var childProcessInfo = new ProcessStartInfo
{
FileName = funcExecutablePath,
Arguments = $"{commandLineArguments} --no-build",
WorkingDirectory = Environment.CurrentDirectory,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
try
{
var childProcess = Process.Start(childProcessInfo);
if (VerboseLogging == true)
{
ColoredConsole.WriteLine(VerboseColor($"Started child process with ID: {childProcess.Id}"));
}
childProcess!.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
ColoredConsole.WriteLine(e.Data);
}
};
childProcess.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
ColoredConsole.WriteLine(ErrorColor(e.Data));
}
};
childProcess.EnableRaisingEvents = true;
childProcess.Exited += (sender, args) =>
{
tcs.SetResult();
};
childProcess.BeginOutputReadLine();
childProcess.BeginErrorReadLine();
_processManager.RegisterChildProcess(childProcess);
childProcess.WaitForExit();
}
catch (Exception ex)
{
throw new CliException($"Failed to start the {(shouldStartNet8ChildProcess ? DotnetConstants.InProc8HostRuntime : DotnetConstants.InProc6HostRuntime)} model host. {ex.Message}");
}
}