954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Executing Shell script from Java code.

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,

new_2_java
Junior Poster
127 posts since Apr 2007
Reputation Points: 7
Solved Threads: 6
 

See this thread .. it should answer all your questions and give you enough examples..

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

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.

new_2_java
Junior Poster
127 posts since Apr 2007
Reputation Points: 7
Solved Threads: 6
 

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

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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,

new_2_java
Junior Poster
127 posts since Apr 2007
Reputation Points: 7
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You