Bookmark Topic Watch Topic
  • New Topic

How to Execute an UNIX shell script from Java application  RSS feed

K Seshan
Posts: 6
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi All,
Iam trying to execute an unix shell(.sh file)from a java code.I tried executing windows batch(.bat) file it executed in style without any probs,but iam struck up when trying to execute an shell script.Could anyone please help me out in how to perform this task.

My Code for bat execution

public class loadNotepad
public static void main(String args[]) throws Exception
System.out.println("Coming Inside the main method");
Runtime load = Runtime.getRuntime();

String sFileName = "C:\\Samples\\Sample_jpotcl\\temp\\enable2trainr\\enableTest.bat";

Process process = load.exec("cmd.exe /C "+sFileName);
//int retVal = process.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null)

System.out.println("Coming outside the main method--->>"+sFileName);
}catch(Exception e){
} // End of class loadNotpad

Your help ia greatly appreciated at this moments

Thanks in Advance
Ernest Friedman-Hill
author and iconoclast
Posts: 24217
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question to more than one forum. It just wastes people's time. I answered the copy in Linux/UNIX, and I'm closing this one.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!