tags:

views:

244

answers:

2

Hi All,

I have a .sh file which i am trying to run using runtime api It runs perfectly if .sh file is under main project folder but I want it to be access from outside the project folder

example:/home/test/test.sh when i try to run this i get /home/test/test.sh not found error Can anyone tell me how to execute .sh file using runtime accessing the file from local system.

A: 

is the .sh file chmoded to be executable?

if its not you could either:

chmod +x /home/test/test.sh

or

when you call the script pass it through sh so:

sh /home/test/test.sh
Arcath
the syntax i am using is String cmd="sh /home/test/test.sh"; Process p = Runtime.getRuntime().exec(cmd);i want to execute the cmd as ./test.sh from project folder keeping .sh file under project folder directly ,i would get an output here.but when i create war file of the project and try to access it i would get .sh not found
sarah
the .class is under web-inf/classes/test/test.class and .sh is under web-inf/classes
sarah
I don't think you will be able to use a relative path: the relative path you need will depend on your Java runtime environment. You are best off setting a configurable runtime env variable such as "BASE_PATH" for your application.
Richard
+1  A: 

Runtime.exec() is not a command line One pitfall to cover with Runtime.exec() is mistakenly assuming that exec() accepts any String that your command line (or shell) accepts. Runtime.exec() is much more limited and not cross-platform. This pitfall is caused by users attempting to use the exec() method to accept a single String as a command line would. The confusion may be due to the fact that command is the parameter name for the exec() method. Thus, the programmer incorrectly associates the parameter command with anything that he or she can type on a command line, instead of associating it with a single program and its arguments.

Anjali