Executing Shell script from Java code.

Reply

Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Executing Shell script from Java code.

 
0
  #1
Jul 4th, 2007
Hi all,

I would like to execute a shell script from my java code. Can some one please tell me if that is possible? Here's what I tried, but with no result.

  1. public class RunPDCC
  2. {
  3. public static void main(String[] args)
  4. {
  5. try
  6. {
  7. Process proc = Runtime.getRuntime().exec("./test.sh");
  8. System.out.println("Print Test Line.");
  9. }
  10. catch (Exception e)
  11. {
  12. System.out.println(e.getMessage());
  13. e.printStackTrace();
  14. }
  15. }
  16. }

In this program, I try to run the "./test.sh" shell script, which-for now-I have, just (echo "Hellow World"). But it doesn't seem that the script runs from within my code.

Can some one please tell me if I am in the right track, and how/if I am able to run the script from within my Java code....

Thanks and regards,
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Executing Shell script from Java code.

 
0
  #2
Jul 5th, 2007
See this thread.. it should answer all your questions and give you enough examples..
Are you Agile.. ?
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Re: Executing Shell script from Java code.

 
0
  #3
Jul 5th, 2007
I followed the link, but it took me to a page that doesn't exist anymore. I got error 404 page doesn't exist.

Can you re-provide the URL again, or explain abit yourself....

Thanks again.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,182
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 481
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Executing Shell script from Java code.

 
0
  #4
Jul 5th, 2007
He-he that is my post, did you get my permision
Anyway post start here http://www.daniweb.com/forums/thread73182.html with all explanations what I'm trying to do
but real progress is on second page http://www.daniweb.com/forums/thread73182-2.html

In my case this was specialy design for Windows platform, so you will need to make few changes if you want other platform
Last edited by peter_budo; Jul 5th, 2007 at 12:01 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Re: Executing Shell script from Java code.

 
0
  #5
Jul 5th, 2007
Thanks for reply,

Basicaly, what I am trying to accomplish here, is that I wrote a custom class, that is going to be used for a custom method in Documentum, to launch a utility, which we need to run on a weekly basis.

I figured that I when I was testing my code with "./test.sh" script, I didn't have e"x"ecute permission on this script. So, after using "chmod" to grant myself the "x" permission, it started working.

Thanks again for participation,
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC