ssg: StaticSiteClient: ShowCmdWindows config impl, custom handler for hidden window, fixes git hang when output is not being read
This commit is contained in:
parent
0c8290e4c8
commit
48564482b5
|
@ -204,7 +204,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void DoSiteBuild()
|
private void DoSiteBuild()
|
||||||
{
|
{
|
||||||
var proc = RunSiteCommand(Config.BuildCommand);
|
string stdout, stderr;
|
||||||
|
var proc = RunSiteCommand(Config.BuildCommand, out stdout, out stderr);
|
||||||
if (proc.ExitCode != 0)
|
if (proc.ExitCode != 0)
|
||||||
{
|
{
|
||||||
throw new BlogClientException(
|
throw new BlogClientException(
|
||||||
|
@ -212,8 +213,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
|
||||||
StringId.SSGBuildErrorText,
|
StringId.SSGBuildErrorText,
|
||||||
Res.Get(StringId.ProductNameVersioned),
|
Res.Get(StringId.ProductNameVersioned),
|
||||||
proc.ExitCode.ToString(),
|
proc.ExitCode.ToString(),
|
||||||
proc.StandardOutput.ReadToEnd(),
|
Config.ShowCmdWindows ? "N/A" : stdout,
|
||||||
proc.StandardError.ReadToEnd()
|
Config.ShowCmdWindows ? "N/A" : stderr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,7 +224,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void DoSitePublish()
|
private void DoSitePublish()
|
||||||
{
|
{
|
||||||
var proc = RunSiteCommand(Config.PublishCommand);
|
string stdout, stderr;
|
||||||
|
var proc = RunSiteCommand(Config.PublishCommand, out stdout, out stderr);
|
||||||
if (proc.ExitCode != 0)
|
if (proc.ExitCode != 0)
|
||||||
{
|
{
|
||||||
throw new BlogClientException(
|
throw new BlogClientException(
|
||||||
|
@ -231,8 +233,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
|
||||||
StringId.SSGPublishErrorText,
|
StringId.SSGPublishErrorText,
|
||||||
Res.Get(StringId.ProductNameVersioned),
|
Res.Get(StringId.ProductNameVersioned),
|
||||||
proc.ExitCode.ToString(),
|
proc.ExitCode.ToString(),
|
||||||
proc.StandardOutput.ReadToEnd(),
|
Config.ShowCmdWindows ? "N/A" : stdout,
|
||||||
proc.StandardError.ReadToEnd()
|
Config.ShowCmdWindows ? "N/A" : stderr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,10 +243,14 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
|
||||||
/// Run a command from the site directory
|
/// Run a command from the site directory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="localCommand">Command to run, releative to site directory</param>
|
/// <param name="localCommand">Command to run, releative to site directory</param>
|
||||||
|
/// <param name="stdout">String which will receive the command stdout</param>
|
||||||
|
/// <param name="stderr">String which will receive the command stderr</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private Process RunSiteCommand(string localCommand)
|
private Process RunSiteCommand(string localCommand, out string outStdout, out string outStderr)
|
||||||
{
|
{
|
||||||
var proc = new Process();
|
var proc = new Process();
|
||||||
|
string stdout = "";
|
||||||
|
string stderr = "";
|
||||||
|
|
||||||
// If a 32-bit process on a 64-bit system, call the 64-bit cmd
|
// If a 32-bit process on a 64-bit system, call the 64-bit cmd
|
||||||
proc.StartInfo.FileName = (!Environment.Is64BitProcess && Environment.Is64BitOperatingSystem) ?
|
proc.StartInfo.FileName = (!Environment.Is64BitProcess && Environment.Is64BitOperatingSystem) ?
|
||||||
|
@ -254,16 +260,47 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
|
||||||
// Set working directory to local site path
|
// Set working directory to local site path
|
||||||
proc.StartInfo.WorkingDirectory = Config.LocalSitePath;
|
proc.StartInfo.WorkingDirectory = Config.LocalSitePath;
|
||||||
|
|
||||||
proc.StartInfo.RedirectStandardError = true;
|
proc.StartInfo.RedirectStandardInput = !Config.ShowCmdWindows;
|
||||||
proc.StartInfo.RedirectStandardOutput = true;
|
proc.StartInfo.RedirectStandardError = !Config.ShowCmdWindows;
|
||||||
proc.StartInfo.CreateNoWindow = true;
|
proc.StartInfo.RedirectStandardOutput = !Config.ShowCmdWindows;
|
||||||
|
proc.StartInfo.CreateNoWindow = !Config.ShowCmdWindows;
|
||||||
proc.StartInfo.UseShellExecute = false;
|
proc.StartInfo.UseShellExecute = false;
|
||||||
|
|
||||||
proc.StartInfo.Arguments = $"/C {localCommand}";
|
proc.StartInfo.Arguments = $"/C {localCommand}";
|
||||||
|
|
||||||
|
if(!Config.ShowCmdWindows)
|
||||||
|
{
|
||||||
|
|
||||||
|
proc.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
|
||||||
|
{
|
||||||
|
if (!String.IsNullOrEmpty(e.Data))
|
||||||
|
{
|
||||||
|
stdout += e.Data;
|
||||||
|
Trace.WriteLine($"StaticSiteClient stdout: {e.Data}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
proc.ErrorDataReceived += new DataReceivedEventHandler((sender, e) =>
|
||||||
|
{
|
||||||
|
if (!String.IsNullOrEmpty(e.Data))
|
||||||
|
{
|
||||||
|
stderr += e.Data;
|
||||||
|
Trace.WriteLine($"StaticSiteClient stderr: {e.Data}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
proc.Start();
|
proc.Start();
|
||||||
|
if(!Config.ShowCmdWindows)
|
||||||
|
{
|
||||||
|
proc.BeginOutputReadLine();
|
||||||
|
proc.BeginErrorReadLine();
|
||||||
|
}
|
||||||
proc.WaitForExit();
|
proc.WaitForExit();
|
||||||
|
|
||||||
// The Process will have all standard output waiting in buffer
|
// The caller will have all output waiting in outStdout and outStderr
|
||||||
|
outStdout = stdout;
|
||||||
|
outStderr = stderr;
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue