Exemple #1
0
        private static Process StartProcess(LaunchParamters parameters)
        {
            var startInfo = new ProcessStartInfo(parameters.FileName)
            {
                UseShellExecute = false, // Must be false to redirect output.
                CreateNoWindow  = true,

                RedirectStandardOutput = true,
                StandardErrorEncoding  = Encoding.UTF8,

                RedirectStandardError  = true,
                StandardOutputEncoding = Encoding.UTF8
            };

            if (parameters.Arguments.Count > 1)
            {
                startInfo.ArgumentList.AddRange(parameters.Arguments);
            }
            else if (parameters.Arguments.Count == 1)
            {
                startInfo.Arguments = parameters.Arguments[0];
            }

            var process = Process.Start(startInfo);

            if (process == null)
            {
                throw new InvalidOperationException("No process was started.");
            }

            return(process);
        }
Exemple #2
0
        private static LaunchParamters ParseLaunchParameters(PythonDictionary pythonDictionary)
        {
            var launchParameters = new LaunchParamters
            {
                FileName = Convert.ToString(pythonDictionary.get("file_name", null)),
                Timeout  = Convert.ToInt32(pythonDictionary.get("timeout", 60000))
            };

            var arguments = pythonDictionary.get("arguments", null);

            if (arguments is string argumentsText)
            {
                launchParameters.Arguments.Add(argumentsText);
            }
            else if (arguments is List argumentsList)
            {
                foreach (var argument in argumentsList)
                {
                    launchParameters.Arguments.Add(Convert.ToString(argument));
                }
            }

            return(launchParameters);
        }