Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chmod from Runtime.Exec

 
B Cooper
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice to know, and thanks for responding with the solution.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic