Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

execute shell script with cygwin

807591Apr 24 2008 — edited Apr 25 2008
Hi,

I'v been reading this posting [http://forum.java.sun.com/thread.jspa?forumID=31&threadID=699276] about how to achieve running a bash script from a java application, but I didn't get it working. Currently my code is
@Action(block = Task.BlockingScope.ACTION)
public void executeTestGenerator() {
	File workDir = new File("c:/cygwin/bin");
        String[] cmdArray = new String[5];
        
	cmdArray[0] = "c:/cygwin/bin/bash";
        cmdArray[1] = "--login";
        cmdArray[2] = "-i";
        cmdArray[3] = "-c";
        cmdArray[4] = "/cygdrive/c/temp/dwhim";
		      
	try {
		Runtime.getRuntime().exec(cmdArray, null, workDir);
		System.out.println("Executing cmd");
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
But nothing happens when I invoke this method. Has anybody an idea how to get this working?

Comments

807591
does the program not print "executing cmd" ?
ok, first, what do you think should happen, and second, what is happening really?

you arent doing anything with the input and output streams of your program.. so i dont know what you expect
807591
I should have been thinking about it a little bit longer. After I added a
waitFor()
and redirected the output as it is described in the article I posted the link to, everything worked as it should.
1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 23 2008
Added on Apr 24 2008
2 comments
321 views