01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: /* $Id: CommandLineTask.java 473861 2006-11-12 03:51:14Z gregor $ */
20:
21: package org.apache.lenya.cms.task;
22:
23: /**
24: * A command line task
25: * @deprecated Use the usecase framework instead.
26: */
27: public class CommandLineTask extends AbstractTask {
28:
29: /**
30: * Execute the task. All parameters must have been set with parameterize().
31: * @see org.apache.lenya.cms.task.Task#execute(java.lang.String)
32: */
33: public void execute(String path) throws ExecutionException {
34: String command = getParameters().getParameter("command",
35: "echo \"Exception: No command parameter\"");
36:
37: try {
38: Process process = Runtime.getRuntime().exec(command);
39:
40: java.io.InputStream in = process.getInputStream();
41: byte[] buffer = new byte[1024];
42: int bytes_read = 0;
43: java.io.ByteArrayOutputStream baout = new java.io.ByteArrayOutputStream();
44:
45: while ((bytes_read = in.read(buffer)) != -1) {
46: baout.write(buffer, 0, bytes_read);
47: }
48:
49: if (baout.toString().length() > 0) {
50: throw new ExecutionException("%%%InputStream:S"
51: + baout.toString() + "END:InputStream%%%");
52: }
53:
54: java.io.InputStream in_e = process.getErrorStream();
55: java.io.ByteArrayOutputStream baout_e = new java.io.ByteArrayOutputStream();
56:
57: while ((bytes_read = in_e.read(buffer)) != -1) {
58: baout_e.write(buffer, 0, bytes_read);
59: }
60:
61: if (baout_e.toString().length() > 0) {
62: throw new ExecutionException("###ErrorStream:START"
63: + baout_e.toString() + "END:ErrorStream###");
64: }
65: } catch (java.io.IOException e) {
66: throw new ExecutionException(e);
67: }
68: }
69: }
|