OSDN Git Service

Merge branch 'master' of ssh://www.deister.jp/mnt/hdb1/git/hayashi
[hayashilib/hayashi.git] / src / jp / co / areaweb / tools / command / Job.java
1 package jp.co.areaweb.tools.command;\r
2 import java.io.*;\r
3 \r
4 public class Job\r
5 {\r
6     public static final boolean debug = false;\r
7 \r
8     public static void execJob(File jobFile) throws IOException {\r
9         execJob(jobFile, null);\r
10     }\r
11 \r
12     public static void execJob(File jobFile, File workDir) throws IOException {\r
13         if (jobFile == null) {\r
14             throw new IOException("実行するジョブファイルが指定されていません。");\r
15         }\r
16         if (debug) {\r
17             System.out.println("[s JobFile] " + jobFile.getName());\r
18         }\r
19 \r
20         FileInputStream fis = new FileInputStream(jobFile);\r
21         BufferedReader dis = new BufferedReader(new InputStreamReader(fis));\r
22         String commandLine;\r
23         Command command = new Command();\r
24         while((commandLine = dis.readLine()) != null) {\r
25             command.setCmd(commandLine);\r
26             command.setWorkDir(workDir);\r
27             command.execCommand();\r
28             System.out.println(command.getOutput());\r
29         }\r
30 \r
31         if (debug) {\r
32             System.out.println("[e JobFile] " + jobFile.getName());\r
33         }\r
34         dis.close();\r
35     }\r
36 \r
37     /** \r
38     *   サンプル\r
39     */\r
40     static public void main(String[] args) {\r
41         if (args.length < 1) {\r
42             System.out.println("exp: java jp.co.areaweb.tools.command.Job [jobFileName]");\r
43             return;\r
44         }\r
45 \r
46         try {\r
47             Job.execJob(new File(args[0]), null);\r
48         }\r
49         catch (Exception e) {\r
50             e.printStackTrace();\r
51         }\r
52     }\r
53 }\r