Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelMayer committed Feb 15, 2022
1 parent d002a40 commit 69d341e
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions Source/Dafny/Compilers/Compiler-js.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,16 @@ public override bool RunTargetProgram(string dafnyProgramName, string targetProg
return SendToNewNodeProcess(dafnyProgramName, targetProgramText, callToMain, targetFilename, otherFileNames, outputWriter);
}

DataReceivedEventHandler ProcessData(TextWriter writer) {
return (sendingProcess, e) => {
if (!((Process)sendingProcess).HasExited) {
writer.WriteLine(e.Data);
} else {
writer.Write(e.Data);
}
};
}

bool SendToNewNodeProcess(string dafnyProgramName, string targetProgramText, string/*?*/ callToMain, string targetFilename, ReadOnlyCollection<string> otherFileNames,
TextWriter outputWriter) {
Contract.Requires(targetFilename != null || otherFileNames.Count == 0);
Expand All @@ -2391,27 +2401,13 @@ bool SendToNewNodeProcess(string dafnyProgramName, string targetProgramText, str
};

try {
using var nodeProcess = Process.Start(psi);
nodeProcess.BeginErrorReadLine();
Process nodeProcess = new Process { StartInfo = psi };
nodeProcess.OutputDataReceived += ProcessData(Console.Out);
nodeProcess.ErrorDataReceived += ProcessData(Console.Error);
nodeProcess.Start();
nodeProcess.BeginOutputReadLine();
nodeProcess.BeginErrorReadLine();

void ProcessErrorData(object sender, DataReceivedEventArgs e) {
if (!nodeProcess.HasExited) {
Console.Error.WriteLine(e.Data);
} else {
Console.Error.Write(e.Data);
}
}

void ProcessOutputData(object sender, DataReceivedEventArgs e) {
if (!nodeProcess.HasExited) {
Console.Out.WriteLine(e.Data);
} else {
Console.Out.Write(e.Data);
}
}
nodeProcess.ErrorDataReceived += ProcessErrorData;
nodeProcess.OutputDataReceived += ProcessOutputData;
foreach (var filename in otherFileNames) {
WriteFromFile(filename, nodeProcess.StandardInput);
}
Expand Down

0 comments on commit 69d341e

Please sign in to comment.