User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 374,023 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,775 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 3532 | Replies: 4
Reply
Join Date: Apr 2007
Posts: 106
Reputation: new_2_java is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Executing Shell script from Java code.

  #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.

public class RunPDCC
{
        public static void main(String[] args)
        {
                try
                {
                        Process proc = Runtime.getRuntime().exec("./test.sh");
                        System.out.println("Print Test Line.");
                }
                catch (Exception e)
                {
                        System.out.println(e.getMessage());
                        e.printStackTrace();
                }
        }
}

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,
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore, India
Posts: 535
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Rep Power: 4
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Executing Shell script from Java code.

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

Re: Executing Shell script from Java code.

  #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  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 1,907
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 9
Solved Threads: 216
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Posting Virtuoso

Re: Executing Shell script from Java code.

  #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 11:01 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Apr 2007
Posts: 106
Reputation: new_2_java is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Re: Executing Shell script from Java code.

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 11:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC