Пример #1
0
 private void WriteStandardInput()
 {
     StandardInput.Write(Options.StandardInput);
     if (Options.AutoCloseStandardInput)
     {
         StandardInput.Close();
     }
 }
Пример #2
0
 public new void Dispose()
 {
     StandardInput.Flush();
     StandardInput.Close();
     if (!WaitForExit(1000))
     {
         Kill();
     }
     if (WaitForExit(1000))
     {
         WaitHandle.WaitAll(_waitHandles);
     }
     base.Dispose();
     _isDisposed = true;
 }
Пример #3
0
        void IDisposable.Dispose()
        {
            if (Disposed)
            {
                return;
            }

            Disposed = true;

            // If the child process has already exited, we simply need to dispose of it
            if (_process.HasExited)
            {
                _process.Dispose();
                return;
            }

            // Closing the jsii Kernel's STDIN is how we instruct it to shut down
            StandardInput.Close();

            try
            {
                // Give the kernel 5 seconds to clean up after itself
                if (!_process.WaitForExit(5_000))
                {
                    // Kill the child process if needed
                    _process.Kill();
                }
            }
            catch (InvalidOperationException)
            {
                // This means the process had already exited, because it was faster to clean up
                // than we were to process it's termination. We still re-check if the process has
                // exited and re-throw if not (meaning it was a different issue).
                if (!_process.HasExited)
                {
                    throw;
                }
            }
        }
Пример #4
0
        public bool Run()
        {
            Start();
            StandardInput.Write("chcp 437" + Environment.NewLine);
            StandardInput.Write("ping 8.8.8.8 -n 1" + Environment.NewLine);
            StandardInput.Close();
            String output = StandardOutput.ReadToEnd();

            WaitForExit();
            Close();
            //var a = from line in output.Split('\n')
            //        where line.IndexOf("Reply from 8.8.8.8: ") != -1
            //        let c =  line.Replace("Reply from 8.8.8.8: ","").Split(' ')
            var list = output.Split('\n').Where(c =>
            {
                return(c.IndexOf("Reply from 8.8.8.8: ") != -1);
            }).Select(c =>
            {
                return(c.Replace("Reply from 8.8.8.8: ", "").Replace("\r", "").Split(' '));
            }).FirstOrDefault();

            if (list != null)
            {
                var dic = list.Select(t =>
                {
                    return(t.Split('='));
                }).Select(m =>
                {
                    return(new { k = m[0], v = m[1] });
                }).ToDictionary(i => i.k, v => v.v);
                if (dic.ContainsKey("time"))
                {
                    return(true);
                }
            }
            return(false);
        }
 public new void Close()
 {
     StandardInput.Close();
     StandardOutput.Close();
     base.Close();
 }