Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling *.sh files in Solaris and Linux from any JAVA application

807606May 2 2007 — edited May 4 2007
Hi everybody !

Question No.1
I want to call some *.sh files from my java application. Is it possible? I have done that in Windows with batch files but unable to do in Solaris and Linux with *.sh files.

Question No.2
I'm launching my Web Application as NT Service in Windows. Is there any way in Solaris and Linux to do the same? I know there are some daemons which can do the same. But I dont know how use/handle them.

The sample code for Windows to call batch file
====================================
  public static boolean callBatchFile(String a_strFilePath) {
    try {
      System.out.println("Running the batch script");
      System.out.println("Batch File Path..: " + a_strFilePath);
      Process tomcat = Runtime.getRuntime().exec("cmd /c start /MIN " +
                                                 a_strFilePath);
      tomcat.waitFor();
      System.out.println("Finished running the batch script");
      return true;
    }
    catch (Exception ex) {
      ex.printStackTrace();
      return false;
    }
  }
Sample Code of batch to start my application as NT Service.
%SystemRoot%\system32\net start myWebApp
exit
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2007
Added on May 2 2007
11 comments
2,718 views