public void RunMultipleArgs()
        {
            var testFileWithPath = Path.Combine(_testDir, @"test4.txt");

            var args = new[]
            {
                new Argument {
                    Name = "/C", Value = "set"
                },
                new Argument {
                    Name = "/A", Value = "(1+10)"
                },
                new Argument {
                    Name = ">>", Value = testFileWithPath
                }
            };

            var input = new RunProcessParameters {
                FileName = _process, Arguments = args
            };
            var options = new RunProcessOptions {
                KillProcessAfterTimeout = false, TimeoutSeconds = 30, RedirectStandardInput = false
            };

            ExecuteProcessCommand.RunProcess(input, options);

            Assert.AreEqual(File.ReadAllText(testFileWithPath), "11");
        }
        public void ExecuteMultipleArgs()
        {
            var testFileWithPath = Path.Combine(_testDir, @"test2.txt");

            var args = new[]
            {
                new Argument {
                    Name = "/C", Value = "set"
                },
                new Argument {
                    Name = "/A", Value = "(1+10)"
                },
                new Argument {
                    Name = ">>", Value = testFileWithPath
                }
            };

            var input = new Input {
                ScriptPath = _process, Arguments = args, WaitForResponse = true, TimeoutSeconds = 6
            };

            ExecuteProcessCommand.ExecuteProcess(input);

            Assert.AreEqual(File.ReadAllText(testFileWithPath), "11");
        }
        private ActualValueDelegate <object> TestBaseTimeoutKill(bool optionsKillProcess)
        {
            var args = new[]
            {
                new Argument {
                    Name = "/C", Value = "timeout 10 /nobreak >NUL"
                }
            };

            var input = new RunProcessParameters {
                FileName = _process, Arguments = args
            };
            var options = new RunProcessOptions {
                KillProcessAfterTimeout = optionsKillProcess, TimeoutSeconds = 5, RedirectStandardInput = false
            };

            return(() => ExecuteProcessCommand.RunProcess(input, options));
        }
        public void ExecuteResult()
        {
            var args = new[]
            {
                new Argument {
                    Name = "/C", Value = "set"
                },
                new Argument {
                    Name = "/A", Value = "(1111+2222)"
                }
            };

            var input = new Input {
                ScriptPath = _process, Arguments = args, WaitForResponse = true, TimeoutSeconds = 6
            };

            var result = ExecuteProcessCommand.ExecuteProcess(input);

            Assert.IsTrue(result.Result.Contains("3333"));
        }
        public void ExecuteScript()
        {
            var testFileWithPath = Path.Combine(_testDir, @"test1.txt");

            var args = new[]
            {
                new Argument {
                    Name = "/C", Value = "echo testi >>" + testFileWithPath
                }
            };
            var input = new Input {
                ScriptPath = _process, Arguments = args, WaitForResponse = true, TimeoutSeconds = 6
            };

            ExecuteProcessCommand.ExecuteProcess(input);

            Assert.IsTrue(File.Exists(testFileWithPath));                                        // Tests if the file is created

            Assert.AreEqual(File.ReadAllText(testFileWithPath), "testi " + Environment.NewLine); // Tests that the cmd.exe is only executed once
        }
        private ActualValueDelegate <object> TestBufferTimeoutKill()
        {
            var testFileWithPath = Path.Combine(_testDir, _inputFile);

            var args = new[]
            {
                new Argument {
                    Name = "/C", Value = $"type {testFileWithPath} && timeout 60 /nobreak >NUL"
                },
            };

            var input = new RunProcessParameters {
                FileName = _process, Arguments = args
            };
            var options = new RunProcessOptions {
                KillProcessAfterTimeout = true, TimeoutSeconds = 30, RedirectStandardInput = false
            };

            return(() => ExecuteProcessCommand.RunProcess(input, options));
        }
        public void ExecuteScriptsAsync()
        {
            var testFileWithPath = Path.Combine(_testDir, @"test3.txt");

            var args = new[]
            {
                new Argument {
                    Name = "/C", Value = "set"
                },
                new Argument {
                    Name = "/A (1+10) >>", Value = testFileWithPath
                }
            };
            var input = new Input {
                ScriptPath = _process, Arguments = args, WaitForResponse = false
            };
            var result = ExecuteProcessCommand.ExecuteProcess(input);

            Assert.IsTrue(result.Status);
            Thread.Sleep(100);
            Assert.AreEqual(File.ReadAllText(testFileWithPath), "11");
        }
        // Test possible STDOUT buffer sync problems
        public void FillSTDOUT()
        {
            var testFileWithPath = Path.Combine(_testDir, _inputFile);

            var args = new[]
            {
                new Argument {
                    Name = "/C", Value = $"type {testFileWithPath}"
                }
            };

            var input = new RunProcessParameters {
                FileName = _process, Arguments = args
            };
            var options = new RunProcessOptions {
                KillProcessAfterTimeout = false, TimeoutSeconds = 30, RedirectStandardInput = false
            };

            var output = ExecuteProcessCommand.RunProcess(input, options);

            Assert.IsTrue(output.Output.Length >= 8096 + 5);
            Assert.IsTrue(output.Output[1234] == 'a');
        }