Exemplo n.º 1
0
        public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            var dir       = args.GetString("dir").GetValue();
            var recursive = false;

            if (args.HasArg("recursive"))
            {
                recursive = args.GetBoolean("recursive").GetValue();
            }
            var include_path = recursive;

            if (args.HasArg("include_path"))
            {
                include_path = args.GetBoolean("include_path").GetValue();
            }
            var include_dirs = false;

            if (args.HasArg("include_dirs"))
            {
                include_dirs = args.GetBoolean("include_dirs").GetValue();
            }
            var result = new ValueList();

            CollectFiles(dir, recursive, include_path, include_dirs, result);
            return(result);
        }
Exemplo n.º 2
0
        public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            var    program   = args.GetString("program").GetValue();
            var    arguments = args.GetList("args").GetValue();
            string work_dir  = null;

            if (args.HasArg("work_dir"))
            {
                work_dir = args.GetString("work_dir").GetValue();
            }
            var echo = false;

            if (args.HasArg("echo"))
            {
                echo = args.GetBoolean("echo").GetValue();
            }
            try
            {
                var list = new StringBuilder();
                list.Append(program).Append(" ");
                foreach (var argument in arguments)
                {
                    list.Append(argument.AsString().GetValue()).Append(" ");
                }
                list.Remove(list.Length - 1, 1);
                var process = new Process();
                var info    = process.StartInfo;
                info.FileName  = program;
                info.Arguments = list.ToString();
                if (work_dir != null)
                {
                    info.WorkingDirectory = work_dir;
                }
                info.CreateNoWindow         = true;
                info.RedirectStandardOutput = true;
                info.RedirectStandardError  = true;
                info.RedirectStandardInput  = true;
                if (echo)
                {
                    System.Console.WriteLine(program + " " + list);
                }
                process.Start();
                process.WaitForExit();
                return(new ValueInt(process.ExitCode));
            } catch (Exception e) {
                throw new ControlErrorException(new ValueString("ERROR"), "Cannot execute " + program + ": " + e.Message, pos);
            }
        }
Exemplo n.º 3
0
        public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            var dir = args.GetString("dir").GetValue();

            if (Directory.Exists(dir))
            {
                return(ValueNull.NULL);
            }
            var with_parents = false;

            if (args.HasArg("with_parents"))
            {
                with_parents = args.GetBoolean("with_parents").GetValue();
            }
            if (with_parents)
            {
                try
                {
                    Directory.CreateDirectory(dir);
                }
                catch
                {
                    throw new ControlErrorException(new ValueString("ERROR"), "Cannot create directory " + dir, pos);
                }
            }
            else
            {
                if (!Directory.GetParent(dir).Exists)
                {
                    throw new ControlErrorException(new ValueString("ERROR"), "Cannot create directory " + dir, pos);
                }

                try
                {
                    Directory.CreateDirectory(dir);
                }
                catch
                {
                    throw new ControlErrorException(new ValueString("ERROR"), "Cannot create directory " + dir, pos);
                }
            }
            return(ValueNull.NULL);
        }