You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by de...@struts.apache.org on 2004/11/27 17:19:57 UTC

[Apache Struts Wiki] Updated: StrutsSolutions

   Date: 2004-11-27T08:19:57
   Editor: DakotaJack <cr...@gmail.com>
   Wiki: Apache Struts Wiki
   Page: StrutsSolutions
   URL: http://wiki.apache.org/struts/StrutsSolutions

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -2,7 +2,7 @@
 
 = INTRODUCTION =
 
-This space is to list persistent or general problems and to provide solutions to persistent problems, large and small.  This space is meant to provide a place to discuss problems as well as to present your solutions.  Please only address problems which are identified consequetively by number and do so by number.  Maybe a better organization principle can follow, but this is delightfully informal and still rigorous.  Have fun!  There is no need for solutions to grapple with one another.  There is plenty of room to provide optional solutions.  Again, have fun!
+This space is to list persistent or general problems and to provide solutions to persistent problems, large and small.  This space is meant to provide a place to discuss problems as well as to present your solutions.  Please only address problems which are identified consequetively by number and do so by number.  Maybe a better organization principle can follow, but this is delightfully informal and still rigorous.  Have fun!  There is no need for solutions to grapple with one another.  There is plenty of room to provide optional solutions.  Again, have fun!  There are no rules here.  Only problems and solutions.  The number of problems in serious coding are limited enough not to have to debate whether this or that problem is properly included here.  If you have a solution to a problem you had coding in relationship to some Struts project, that is good enough.  I will start off with a solution to the problem of running scripts in Java, which I recently had to solve on an app that needed hot deploy in Struts.  That is a tangential problem and such problems and solutions will be welcome.  "No holds barred" in this arena!
 
 
 
@@ -22,6 +22,8 @@
 
 2. Caching images
 
+3. Running Scripts from Java Classes
+
 == DISCUSSION OF PROBLEMS (What Is The Problem?) ==
 
 == DISCUSSION OF SOLUTIONS (What Is The Solution?) ==
@@ -31,3 +33,88 @@
 == SOLUTIONS ==
 
 1.A. Frank Zammetties !DownloadAction App
+
+3.A.  Found Somewhere Online: Dakota Jack
+{{{
+package deploy;
+
+public class ScriptExec {
+  public static void main(String args[]) {
+    if (args.length < 1) {
+      System.out.println("USAGE: java GoodWindowsExec <cmd>");
+      System.exit(1);
+    }
+
+    try {
+      String osName = System.getProperty("os.name");
+      String[] cmd = new String[3];
+
+      if(osName.equals("Windows XP")) {
+        cmd[0] = "cmd.exe" ;
+        cmd[1] = "/C" ;
+        cmd[2] = args[0];
+      } else if(osName.equals("Windows NT")) {
+        cmd[0] = "cmd.exe" ;
+        cmd[1] = "/C" ;
+        cmd[2] = args[0];
+      } else if(osName.equals("Windows 95")) {
+        cmd[0] = "command.com" ;
+        cmd[1] = "/C" ;
+        cmd[2] = args[0];
+      }
+
+      Runtime rt = Runtime.getRuntime();
+      System.out.println("Execing " + cmd[0] + " " + cmd[1]
+                 + " " + cmd[2]);
+      Process proc = rt.exec(cmd);
+      // any error message?
+      StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
+
+      // any output?
+      StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
+
+      // kick them off
+      errorGobbler.start();
+      outputGobbler.start();
+
+      // any error???
+      int exitVal = proc.waitFor();
+      System.out.println("ExitValue: " + exitVal);
+    } catch (Throwable t) {
+      t.printStackTrace();
+    }
+  }
+}
+
+
+package deploy;
+
+import java.util.*;
+import java.io.*;
+
+class StreamGobbler
+    extends Thread {
+  private InputStream is;
+  private String      type;
+
+  StreamGobbler(InputStream is,
+                String      type) {
+    this.is   = is;
+    this.type = type;
+  }
+
+  public void run() {
+    try {
+      InputStreamReader isr = new InputStreamReader(is);
+      BufferedReader br = new BufferedReader(isr);
+      String line=null;
+      while ((line = br.readLine()) != null)
+        System.out.println(type + ">" + line);
+    } catch (IOException ioe) {
+      ioe.printStackTrace();
+    }
+  }
+}
+}}}
+
+= THE END =

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org