<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace LetsEncrypt.ACME.Simple.Clients
{
    public class ScriptClient : Plugin
    {
        public const string PluginName = "Manual";
        public override string Name => PluginName;

        public static void RunScript(string script, string parameterTemplate, params string[] parameters)
        {
            if (!string.IsNullOrWhiteSpace(script) && !string.IsNullOrWhiteSpace(parameterTemplate))
            {
                var parametersFormat = string.Format(parameterTemplate, parameters);
                Program.Log.Information(true, "Running {script} with {parameters}", script, parametersFormat);
                Process.Start(script, parametersFormat);
            }
            else if (!string.IsNullOrWhiteSpace(script))
            {
                Program.Log.Information(true, "Running {script}", script);
                Process.Start(script);
            }
            else
            {
                Program.Log.Warning("Unable to configure server software.");
            }
        }

        public override void Install(Target target, string pfxFilename, X509Store store, X509Certificate2 newCertificate, X509Certificate2 oldCertificate)
        {
            RunScript(
                Program.Options.Script,
                Program.Options.ScriptParameters,
                target.Host,
                Properties.Settings.Default.PFXPassword,
                pfxFilename,
                store.Name,
                newCertificate.FriendlyName,
                newCertificate.Thumbprint);
        }

        public override void Install(Target target)
        {
            RunScript(
                Program.Options.Script,
                Program.Options.ScriptParameters,
                target.Host,
                Properties.Settings.Default.PFXPassword, 
                Program.Options.CentralSslStore);
        }
    }
}<commit_msg>Wait for process to exit and warn on non-zero exit code (Fix #599)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace LetsEncrypt.ACME.Simple.Clients
{
    public class ScriptClient : Plugin
    {
        public const string PluginName = "Manual";
        public override string Name => PluginName;

        public static void RunScript(string script, string parameterTemplate, params string[] parameters)
        {
            Process process = null;
            if (!string.IsNullOrWhiteSpace(script) && !string.IsNullOrWhiteSpace(parameterTemplate))
            {
                var parametersFormat = string.Format(parameterTemplate, parameters);
                Program.Log.Information(true, "Running {script} with {parameters}", script, parametersFormat);
                process = Process.Start(script, parametersFormat);
            }
            else if (!string.IsNullOrWhiteSpace(script))
            {
                Program.Log.Information(true, "Running {script}", script);
                process = Process.Start(script);
            }
            else
            {
                Program.Log.Warning("Unable to configure server software.");
            }
            if (process != null)
            {
                process.WaitForExit();
                if (process.ExitCode != 0)
                {
                    Program.Log.Warning("Process finished with exitcode {code}", process.ExitCode);
                }
            }
            
        }

        public override void Install(Target target, string pfxFilename, X509Store store, X509Certificate2 newCertificate, X509Certificate2 oldCertificate)
        {
            RunScript(
                Program.Options.Script,
                Program.Options.ScriptParameters,
                target.Host,
                Properties.Settings.Default.PFXPassword,
                pfxFilename,
                store.Name,
                newCertificate.FriendlyName,
                newCertificate.Thumbprint);
        }

        public override void Install(Target target)
        {
            RunScript(
                Program.Options.Script,
                Program.Options.ScriptParameters,
                target.Host,
                Properties.Settings.Default.PFXPassword, 
                Program.Options.CentralSslStore);
        }
    }
}
{'fraction_non_alphanumeric': 0.07924693520140105, 'fraction_numerical': 0.0070052539404553416, 'mean_word_length': 1.7791970802919708, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4731329', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1018, 'n_words': 232}