KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > utils > JahiaCmdExec


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
// JahiaCmdExec
15
//
16
// NK 13.01.2001
17
//
18
//
19

20 package org.jahia.utils;
21
22
23 import java.io.File JavaDoc;
24
25 import org.jahia.exceptions.JahiaException;
26
27 /**
28  * Execute an External Command Line
29  *
30  * @author Khue ng
31  */

32 public class JahiaCmdExec {
33
34    protected String JavaDoc m_Cmd = "";
35
36    /**
37     * Constructor
38     *
39     * @param (String) cmd, the command line
40     */

41    public JahiaCmdExec(String JavaDoc cmd) {
42
43       m_Cmd = cmd;
44
45    }
46
47
48    /**
49     * Execute the command in the current working dir
50     *
51     * @exception (JahiaException) on error
52     */

53    public void execute() throws JahiaException {
54
55       try {
56
57          Process JavaDoc process = Runtime.getRuntime().exec(m_Cmd);
58
59       } catch (Exception JavaDoc e) {
60
61          String JavaDoc errMsg = "Failed executing command line " + m_Cmd ;
62          JahiaConsole.println("JahiaCmdExec::execute()", errMsg + "\n" + e.toString());
63          throw new JahiaException ("JahiaCmdExec", errMsg ,
64                                     JahiaException.SERVICE_ERROR, JahiaException.WARNING_SEVERITY, e);
65
66       }
67    }
68
69
70    /**
71     * Execute the command in a specified working dir
72     *
73     * @param (File) workingDir , The abstract File object to the new working dir
74     * @exception (JahiaException) on error
75     */

76    public void execute(File JavaDoc workingDir) throws JahiaException {
77
78       try {
79          Process JavaDoc process = Runtime.getRuntime().exec(m_Cmd,new String JavaDoc[]{""},workingDir);
80
81       } catch (Exception JavaDoc e) {
82
83          String JavaDoc errMsg = "Failed executing command line " + m_Cmd ;
84          JahiaConsole.println("JahiaCmdExec::execute()", errMsg + "\n" + e.toString());
85          throw new JahiaException ("JahiaCmdExec", errMsg ,
86                                     JahiaException.SERVICE_ERROR, JahiaException.WARNING_SEVERITY, e);
87
88       }
89    }
90
91
92 }
93
94
Popular Tags