Ejemplo n.º 1
0
        public NpmScriptRunner(
            string workingDirectory,
            string scriptName,
            IDictionary <string, string> envVars)
        {
            if (string.IsNullOrEmpty(workingDirectory))
            {
                throw new ArgumentException("Cannot be null or empty.", nameof(workingDirectory));
            }
            if (string.IsNullOrEmpty(scriptName))
            {
                throw new ArgumentException("Cannot be null or empty.", nameof(scriptName));
            }
            string fileName = "npm";
            string str      = "run " + scriptName;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                fileName = "cmd";
                str      = "/c npm " + str;
            }
            ProcessStartInfo startInfo = new ProcessStartInfo(fileName)
            {
                Arguments              = str,
                UseShellExecute        = false,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                WorkingDirectory       = workingDirectory
            };

            if (envVars != null)
            {
                foreach (KeyValuePair <string, string> envVar in (IEnumerable <KeyValuePair <string, string> >)envVars)
                {
                    startInfo.Environment[envVar.Key] = envVar.Value;
                }
            }
            Process process = NpmScriptRunner.LaunchNodeProcess(startInfo);

            this.StdOut = new EventedStreamReader(process.StandardOutput);
            this.StdErr = new EventedStreamReader(process.StandardError);
        }
 public EventedStreamStringReader(EventedStreamReader eventedStreamReader)
 {
     this._eventedStreamReader = eventedStreamReader ?? throw new ArgumentNullException(nameof(eventedStreamReader));
     this._eventedStreamReader.OnReceivedLine += new EventedStreamReader.OnReceivedLineHandler(this.OnReceivedLine);
 }