Exemple #1
0
        protected override void ExecuteJob(IJobExecutionContext context)
        {
            Process      pro  = null;
            StreamWriter sIn  = null;
            StreamReader sOut = null;
            string       command;

            try
            {
                var dataMap = context.MergedJobDataMap;
                ShellCommand = dataMap.GetString("shell-command");
                ShellName    = dataMap.GetString("shell-name");
                OutFolder    = dataMap.GetString("out-folder");
                FileName     = dataMap.GetString("file-name");
                FileFormat   = dataMap.GetString("file-format");
                FileExt      = dataMap.GetString("file-ext");
                string fileName = Path.Combine(OutFolder, string.Concat(FileName, DateTime.Now.ToString(FileFormat), ".", FileExt));
                command = ShellCommand.Replace("{fileName}", fileName);
                Logger.Info($"[命令]-- {command}");
                if (!Directory.Exists(OutFolder))
                {
                    Directory.CreateDirectory(OutFolder);
                }
                var result = ShellUtil.ExecuteCommand(ShellName, p =>
                {
                    p(command);
                    p("exit 0");
                }, null);
                string message = result ? fileName : "失败";
                Logger.Info($@"[结果]-- {message}");
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }