Ejemplo n.º 1
0
        /// <summary>
        /// get first line and run it
        /// </summary>
        /// <param name="main"></param>
        /// <param name="util"></param>
        /// <param name="token"></param>
        public void MakeTaskFromLine(MainForm main, Utilities util, CancellationToken token, String line)
        {
            // get the first word in the line (should be name of file that will be executed always)
            cmdFilename = util.getFileName(line);

            // get everything but the first word in line
            arguments = util.getArguments(line);

            // create a new process object "cmd"
            cmd = new System.Diagnostics.Process();

            // pass the fileName to be executed
            cmd.StartInfo.FileName = cmdFilename;
            // pass the arguments for the file
            cmd.StartInfo.Arguments = arguments;

            // Setting this property to false enables you to redirect input, output, and error streams.
            cmd.StartInfo.UseShellExecute = false;

            // dont create a cmd window
            cmd.StartInfo.CreateNoWindow = true;

            // enable redirecting of output from cmd to our textbox
            cmd.StartInfo.RedirectStandardOutput = true;

            // enable redirecting of input to the cmd
            cmd.StartInfo.RedirectStandardInput = true;

            // enable redirecting of error output
            cmd.StartInfo.RedirectStandardError = true;

            // start the process
            cmd.Start();

            try
            {
                // create a new task for output, because ffmpeg prints to error stream, account for that, else print normally
                Task task_output = new Task(() =>
                {
                    if (cmdFilename.Contains("ffmpeg"))
                        Stderr(main, token, cmd, stderr);
                    else
                    {
                        Stdout(main, token, cmd, stdout);
                        Stderr(main, token, cmd, stderr);
                    }

                }, token, TaskCreationOptions.AttachedToParent);

                task_output.Start();
            }
            catch (Exception e)
            {
                textOutput.AppendText(DateTime.Now.ToString("HH:mm:ss tt") + " - Output Thread Error: " + e.Message + "\n");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// run cmd, the commands will be executed in sequence, first line will execute and program will wait until its complete, then second line etc..
        /// </summary>
        public void runCmd(MainForm main, CancellationToken token)
        {
            // objects
            Utilities util = new Utilities();

            try
            {
                // store all the lines in textbox into cmdTextInput.Lines[] array
                main.cmdTextInput.Lines.ToArray();

                // for each line in text input, a task will be created, a while loop ensures that a task has to be completed before next one begins
                foreach (String line in main.cmdTextInput.Lines)
                {
                    Task task_cmd = Task.Factory.StartNew(delegate
                    { MakeTaskFromLine(main, util, token, line); }, token);

                    while (!task_cmd.IsCompleted)
                    {
                        Thread.Sleep(10);
                    }

                    main.textOutput.AppendText(DateTime.Now.ToString("HH:mm:ss tt") + " - Done.\n");
                }

            } // end try
            catch (Exception e)
            {
                main.textOutput.AppendText(DateTime.Now.ToString("HH:mm:ss tt") + " - CMD Error: " + e.Message + "\n");
            }
        }
Ejemplo n.º 3
0
        private void outputLocationCmdText_Click(object sender, EventArgs e)
        {
            // Displays a SaveFileDialog so the user can save
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "Encoded output|*.mp4";
            saveFileDialog1.Title = "Choose save location for encoded file";
            saveFileDialog1.ShowDialog();

            if (saveFileDialog1.FileName != "")
            {
                Utilities util = new Utilities();
                util.SetOutputPath(this, saveFileDialog1.FileName);
            }
        }