File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Chmod from Runtime.Exec" Watch "Chmod from Runtime.Exec" New topic

Chmod from Runtime.Exec

B Cooper

Joined: Oct 13, 2003
Posts: 2
Hello All I have a interesting situation where I'm trying to run a shell script 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");
//i check the file permissions using the os and it is changed
Process proc1 = Runtime.getRuntime().exec("");
//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?


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

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.

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="" target="_blank" rel="nofollow"></a> down for a while...
I agree. Here's the link:
subject: Chmod from Runtime.Exec
It's not a secret anymore!