Exemple #1
0
        private void fillFilenameAndArguments(ProcessStartInfo pi, string args)
        {
            StringBuilder cmBuilder = new StringBuilder(args);
            string        extra     = ShellArg.GetCommandLine(Context, Args);

            if (!string.IsNullOrEmpty(extra))
            {
                if (args.Length > 0)
                {
                    cmBuilder.Append(" ");
                }
                cmBuilder.Append(extra);
            }

            string cmdLine = cmBuilder.ToString().TrimStart();

            if (cmdLine.StartsWith("\"", StringComparison.Ordinal))
            {
                int n = cmdLine.IndexOf("\"", 1, StringComparison.Ordinal);
                pi.FileName  = cmdLine.Substring(1, n - 1);
                pi.Arguments = cmdLine.Substring(n + 1);
            }
            else
            {
                int n = cmdLine.IndexOf(" ", StringComparison.Ordinal);
                if (n == -1)
                {
                    pi.FileName  = cmdLine;
                    pi.Arguments = string.Empty;
                }
                else
                {
                    pi.FileName  = cmdLine.Substring(0, n);
                    pi.Arguments = cmdLine.Substring(n + 1);
                }
            }
        }
Exemple #2
0
        /// Execute action
        public override object Execute()
        {
            try
            {
                // Prepare parameters
                List <string> p = new List <string>();
                var           o = GetTransformedValue();
                if (o is Array)
                {
                    foreach (var elem in (Array)o)
                    {
                        if (elem != null)
                        {
                            p.Add(Utils.To <string>(elem));
                        }
                    }
                }
                else
                {
                    string v = Utils.To <string>(o);
                    if (!string.IsNullOrEmpty(v))
                    {
                        p.AddRange(Utils.SplitArgs(v));
                    }
                    p.AddRange(ShellArg.GetParams(Context, Args));
                }

                // Choose script
                string incId    = Context.TransformStr(IncludeId, Transform);
                string scriptId = Context.TransformStr(ScriptId, Transform);
                if (!string.IsNullOrEmpty(scriptId))
                {
                    _loadedScript = Context.Find <Script>(scriptId);
                    if (_loadedScript == null)
                    {
                        throw new ParsingException("A subroutine with id=" + scriptId + " was not found");
                    }
                }
                else if (!string.IsNullOrEmpty(incId))
                {
                    _loadedScript = Context.Find <Include>(incId).IncludedScript;
                    if (_loadedScript == null)
                    {
                        throw new ParsingException("An include directive with id=" + scriptId + " was not found");
                    }
                }
                else
                {
                    string f = Context.TransformStr(From, Transform);
                    if (string.IsNullOrEmpty(From))
                    {
                        if (p.Count > 0)
                        {
                            f = p[0];
                            p.RemoveAt(0);
                        }
                        else
                        {
                            throw new ScriptRuntimeException("Script not specified");
                        }
                    }
                    string fFound = Context.FindScriptPartFileName(f, Context.TransformStr(Path, Transform));
                    if (fFound != null)
                    {
                        f = fFound;
                    }
                    _loadedScript = Context.LoadScript(f, ValidateSignature);
                    Context.Initialize(_loadedScript);
                }
                // Execute script
                Context.OutTo(Context.TransformStr(OutTo, Transform), Context.ExecuteScript(_loadedScript, p, Isolation));
                return(null);
            }
            finally
            {
                _loadedScript = null;
            }
        }