1

Is it possible to Run Shell script in java program. I am using windows XP as my operating system.

Thanks in Advance.

Code Hungry
  • 3,930
  • 22
  • 67
  • 95

3 Answers3

2

Yes, take a look at Runtime.getRuntime().exec()

iamkrillin
  • 6,798
  • 1
  • 24
  • 51
1

In general, it is not possible to run a shell script in Java. However, you can run the script from Java, provided that the shell is installed on your machine along with the commands mentioned in the shell script.

I take it that you want to run a UNIX shell script on your Windows XP machine. If that is the case, you need to install something like Cygwin.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Can i use Cygwin as a part of my java Application. if i want to use sme application on different machine without installing Cygwin. Is it possible. – Code Hungry Nov 16 '11 at 04:36
  • No. It is not possible. You will need to rewrite the script as a BAT file that uses native windows commands. – Stephen C Nov 16 '11 at 05:42
1

Have a look at this tutorial http://www.rgagnon.com/javadetails/java-0014.html

I believe this question is duplicate of below post

How to run Unix shell script from Java code?

Community
  • 1
  • 1
questborn
  • 2,735
  • 2
  • 16
  • 17