This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Chmod from Runtime.Exec Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Chmod from Runtime.Exec" Watch "Chmod from Runtime.Exec" New topic
Author

Chmod from Runtime.Exec

B Cooper
Greenhorn

Joined: Oct 13, 2003
Posts: 2
Hello All I have a interesting situation where I'm trying to run a shell script test.sh from my web application (I have already informed my client of the security risk assocaited with this).

I'm trying to do a simple chmod 777 before I try to execute the shell script to insure that it has the execute bit is set.

So I do something similar to the below.

Process proc0 = Runtime.getRuntime().exec("chmod 777 test.sh");
//i check the file permissions using the os and it is changed
Process proc1 = Runtime.getRuntime().exec("test.sh");
//doesn't work

BUT if I run the same statements again from a 2nd web page IT works.

It's like in the same request that chmod mod didn't take effect, even though at the OS level it did?

Anyone have any ideas?

Thanks,
Coop

[ May 13, 2004: Message edited by: B Cooper ]
B Cooper
Greenhorn

Joined: Oct 13, 2003
Posts: 2
Found out that the call is asynchronous and I needed a waitFor call against the process object to ensure it completed the chmod 777 first before the script call.

thanks,
Coop
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
Nice to know, and thanks for responding with the solution.


SCJP, SCWCD, SCBCD, IBM CSD WebSphere v5, <br />A+, MCP 2000 and 2000 server, CST, and few incompleted certification tracks.<br /> <br />Ivory Coast<br /> <br />Analyze your web Request/Response @ <a href="http://webtools.servehttp.com" target="_blank" rel="nofollow">http://webtools.servehttp.com</a> down for a while...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chmod from Runtime.Exec
 
Similar Threads
Error while executing shell script from java
runnning a shell script from mac os x
Re : Run Linux Shell script in Java
declaring the shell variable
IOException while executing runtime.exec