executing shell script from java application
hi,i want to know is there any way of executing a shell script from my java application? please help me........
|
read about method exec() at java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
quick example how to execute 'ls' command Runtime.getRuntime().exec("ls -l"); |
Thank u bartekg.......
i have read the description given for runtime and i've tried executing the program as below: Public class ExecCMD{ psvm(S a[]){ try{ Runtime r=Runtime.getRuntime(); Process p=r.exec("sh xyz.sh"); }catch(Exception e){ ....... } } } when i run this code i didn't get the o/p as the shell should print a string.So,i have changed my shell to redirect the o/p to a file i.e xyz.sh: echo "abcdef" > abc.txt so after running the above java program i got a file named abc.txt which contains the string abcdef.this shows that my shell is running. But what my problem is, i must give input from an interface created by java program to a shell script.(dynamically) i' m very thankful to u plz reply me soon |
One way to do it is to create a file-system pipe (man mkfifo). Have the script read from it, and have the java program write to it.
|
Another way would be using the Runtime.getInput/Output/ErrorStream() methods.
|
Moved: This thread is more suitable in <PORGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
All times are GMT -5. The time now is 06:51 AM. |