瀏覽代碼

Merge pull request #289 from valinz/script-job-close-logfile

许雪里 7 年之前
父節點
當前提交
548b367c78
沒有帳戶連結到提交者的電子郵件
共有 1 個文件被更改,包括 15 次插入14 次删除
  1. 15 14
      xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java

+ 15 - 14
xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java 查看文件

@@ -59,22 +59,23 @@ public class ScriptUtil {
59 59
         // 标准输出:print (null if watchdog timeout)
60 60
         // 错误输出:logging + 异常 (still exists if watchdog timeout)
61 61
         // 标准输入
62
-        FileOutputStream fileOutputStream = new FileOutputStream(logFile, true);
63
-        PumpStreamHandler streamHandler = new PumpStreamHandler(fileOutputStream, fileOutputStream, null);
62
+        try (FileOutputStream fileOutputStream = new FileOutputStream(logFile, true)) {
63
+            PumpStreamHandler streamHandler = new PumpStreamHandler(fileOutputStream, fileOutputStream, null);
64 64
 
65
-        // command
66
-        CommandLine commandline = new CommandLine(command);
67
-        commandline.addArgument(scriptFile);
68
-        if (params!=null && params.length>0) {
69
-            commandline.addArguments(params);
70
-        }
65
+            // command
66
+            CommandLine commandline = new CommandLine(command);
67
+            commandline.addArgument(scriptFile);
68
+            if (params!=null && params.length>0) {
69
+                commandline.addArguments(params);
70
+            }
71 71
 
72
-        // exec
73
-        DefaultExecutor exec = new DefaultExecutor();
74
-        exec.setExitValues(null);
75
-        exec.setStreamHandler(streamHandler);
76
-        int exitValue = exec.execute(commandline);  // exit code: 0=success, 1=error
77
-        return exitValue;
72
+            // exec
73
+            DefaultExecutor exec = new DefaultExecutor();
74
+            exec.setExitValues(null);
75
+            exec.setStreamHandler(streamHandler);
76
+            int exitValue = exec.execute(commandline);  // exit code: 0=success, 1=error
77
+            return exitValue;
78
+        }
78 79
     }
79 80
 
80 81
 }