We are currently experimenting with using the cook
commandlet to cook assets on our build system.
The commandlet is run from a CMD shell on Windows but right after starting it does open its own console window where it displays its output.
Since we are running it from a command line environment such as a build server we want it to output directly to the initial stdout channel instead of this additional console window.
Looking at the FEngineLoop::PreInit
method, it looked like adding -stdout
as a command line switch on the commandlet would cause it to really use the initial stdout channel but this does not change a thing and looking at the code further seems to indicate that the whole commandlet actually redirects all “stdout” output to its own custom output window.
Is there a way to disable this highly undesirable behaviour?
There is no need to open an additional console window when already launched from a command line shell. Also, many build environments do actually not allow windows to be opened (when run as services for instance on Windows) so I suspect that this might cause issues in these cases.
This works in C#, you could write your own wrapper that handles output as you want (in this case it directs it to Log, after the invoke which would probably be needless in a simple console app.
void StartProcess(string toolExeOrBatch, string cmdline)
{
System.Diagnostics.ProcessStartInfo oStartInfo = new System.Diagnostics.ProcessStartInfo();
oStartInfo.FileName = toolExeOrBatch;
oStartInfo.Arguments = cmdline;
oStartInfo.ErrorDialog = true;
oStartInfo.RedirectStandardOutput = true;
oStartInfo.UseShellExecute = false;
oStartInfo.CreateNoWindow = true;
System.Diagnostics.Process process = System.Diagnostics.Process.Start(oStartInfo);
process.OutputDataReceived += ToolOutputHandler;
process.BeginOutputReadLine();
while (!process.HasExited)
{
Application.DoEvents(); // This keeps your form responsive by processing events
}
bool bSuccess = process.ExitCode != 0;
if(bSuccess)
{
Log("Calling External Process- Completed!");
}
else
{
Log("Calling External Process- FAILED! Return code: " + process.ExitCode.ToString());
}
process.Close();
................
private void ToolOutputHandler(object sendingProcess, System.Diagnostics.DataReceivedEventArgs outLine)
{
if (richTextBox_Output.InvokeRequired)
{
richTextBox_Output.BeginInvoke(
new System.Diagnostics.DataReceivedEventHandler(ToolOutputHandler), new[] { sendingProcess, outLine }
);
}
else
{
if (outLine.Data != null)
{
Log(outLine.Data);
}
}
}