Exemple #1
0
        private void button6_Click(object sender, EventArgs e)
        {
            string file = "igothoeeeeees";

            Process.Start(file);

            Process cmd = new Process();

            cmd.StartInfo.FileName = "cmd.exe";
            cmd.StartInfo.RedirectStandardInput  = true;
            cmd.StartInfo.RedirectStandardOutput = true;
            cmd.StartInfo.CreateNoWindow         = false;
            cmd.StartInfo.UseShellExecute        = false;
            cmd.Start();

            cmd.StandardInput.WriteLine("@@echo off");
            cmd.StandardInput.WriteLine("rem Hostname change");
            cmd.StandardInput.WriteLine("SET TextFile = D:\antiOS\host.txt");
            cmd.StandardInput.WriteLine("ipconfig /renew");
            cmd.StandardInput.WriteLine("ipconfig /flushdns");
            cmd.StandardInput.Flush();
            cmd.StandardInput.Close();
            cmd.WaitForExit();
            Console.WriteLine(cmd.StandardOutput.ReadToEnd());
        }
Exemple #2
0
        public new bool Start()
        {
            var result = base.Start();

            StandardInput.WriteLine(@"git pull origin master");
            StandardInput.WriteLine(@"exit");
            return(result);
        }
Exemple #3
0
        public RunResult Run(string arguments, string input)
        {
            StartInfo.Arguments = arguments;
            Start();

            if (!string.IsNullOrEmpty(input))
            {
                StandardInput.WriteLine(input);
            }

            var runResult = CreateRunResult();

            WaitForExit();
            return(runResult);
        }
Exemple #4
0
 protected void SendYesForBatPrompt()
 {
     if (!StopRequested)
     {
         return;
     }
     if (ProcessName == "cmd")
     {
         try
         {
             StandardInput.WriteLine("Y");
         }
         //best effort
         catch (InvalidOperationException) { }
     }
 }
Exemple #5
0
 static void Main()
 {
     ProcessStartInfo startInfo = new ProcessStartInfo();
         startInfo.FileName = "cmd.exe";
         startInfo.Arguments = "/c C:\\Windows\\System32\\cmd.exe";
         startInfo.RedirectStandardInput = true;
         startInfo.RedirectStandardOutput = true;
         startInfo.RedirectStandardError = true;
         startInfo.UseShellExecute = false;
         startInfo.Verb = "RunAs";
     Process process = new Process();
         process.StartInfo = startInfo;
         process.Start();
         process.StandardInput.WriteLine("bcdedit /bootsequence {4a820782-35aa-11e1-b8e6-80978f9fdf9a} {current} {bootmgr} "); '一定要在最後面加上bootmgr
         process.StandardInput.WriteLine("exit");
         process.WaitForExit();
 }
Exemple #6
0
        void IDisposable.Dispose()
        {
            if (Disposed)
            {
                return;
            }

            Disposed = true;

            using (_process)
            {
                if (!_process.HasExited)
                {
                    // Write "exit" message
                    StandardInput.WriteLine("{\"exit\":0}");
                    ;
                }

                StandardInput.Dispose();
                StandardOutput.Dispose();

                // Give the STDERR sink thread 5 seconds to finish consuming outstanding buffers
                _stderrSink.Join(5_000);

                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;
                    }
                }
            }
        }
Exemple #7
0
        public void StartAndWait(bool asyncOutput, Action <Process> postStartAction = null)
        {
            Start();

            if (asyncOutput)
            {
                BeginErrorReadLine();
                BeginOutputReadLine();
            }

            StandardInput.WriteLine(Environment.NewLine);

            if (postStartAction != null)
            {
                postStartAction(this);
            }

            WaitForExit(); // TODO timeout?
        }
        /// <summary>
        /// Kills the transcoding job.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="closeLiveStream">if set to <c>true</c> [close live stream].</param>
        /// <param name="delete">The delete.</param>
        private async Task KillTranscodingJob(TranscodingJobDto job, bool closeLiveStream, Func <string, bool> delete)
        {
            job.DisposeKillTimer();

            _logger.LogDebug("KillTranscodingJob - JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId);

            lock (_activeTranscodingJobs)
            {
                _activeTranscodingJobs.Remove(job);

                if (job.CancellationTokenSource?.IsCancellationRequested == false)
                {
                    job.CancellationTokenSource.Cancel();
                }
            }

            lock (_transcodingLocks)
            {
                _transcodingLocks.Remove(job.Path !);
            }

            lock (job.ProcessLock !)
            {
                #pragma warning disable CA1849 // Can't await in lock block
                job.TranscodingThrottler?.Stop().GetAwaiter().GetResult();

                var process = job.Process;

                var hasExited = job.HasExited;

                if (!hasExited)
                {
                    try
                    {
                        _logger.LogInformation("Stopping ffmpeg process with q command for {Path}", job.Path);

                        process !.StandardInput.WriteLine("q");

                        // Need to wait because killing is asynchronous.
                        if (!process.WaitForExit(5000))
                        {
                            _logger.LogInformation("Killing FFmpeg process for {Path}", job.Path);
                            process.Kill();
                        }
                    }
                    catch (InvalidOperationException)
                    {
                    }
                }
                #pragma warning restore CA1849
            }

            if (delete(job.Path !))
            {
                await DeletePartialStreamFiles(job.Path !, job.Type, 0, 1500).ConfigureAwait(false);
            }

            if (closeLiveStream && !string.IsNullOrWhiteSpace(job.LiveStreamId))
            {
                try
                {
                    await _mediaSourceManager.CloseLiveStream(job.LiveStreamId).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error closing live stream for {Path}", job.Path);
                }
            }
        }
Exemple #9
0
 public void WriteLine(string command, params object[] args0)
 {
     StandardInput.WriteLine(string.Format("{0} 1>NUL", command), args0);
 }
 public void ExecuteCommand(string testItemCommand)
 {
     StandardInput.WriteLine(testItemCommand);
     _executedCommands.Add(testItemCommand);
 }
Exemple #11
0
 public virtual void Send(string data)
 {
     StandardInput.WriteLine(data);
 }