# Call to sudo

**URL:** <https://www.ruby-forum.com/t/call-to-sudo/151227>\
**Category:** Ruby\
**Created:** [October 18, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/call-to-sudo/151227 "2008-10-18T16:43:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [October 18, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/call-to-sudo/151227/1 "2008-10-18T16:43:02Z")

</div>

Is possible to call to sudo before of run a ruby statement (for that  
can be run that statement)?

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [October 18, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/call-to-sudo/151227/2 "2008-10-18T16:48:19Z")

</div>

Hi Kless.

I think you’re talking about passing commands through the ‘system’  
command.  
How about something like this:

system(“sudo rm -rf /path/to/directory”)

James

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [October 18, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/call-to-sudo/151227/3 "2008-10-18T17:18:15Z")

</div>

On 18 oct, 15:47, James H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Kless.
> 
> I think you’re talking about passing commands through the ‘system’ command.  
> How about something like this:
> 
> system(“sudo rm -rf /path/to/directory”)

So, is not possible anything as: ?

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [October 18, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/call-to-sudo/151227/4 "2008-10-18T17:25:17Z")

</div>

Kless wrote:

> So, is not possible anything as: ?

> system(“sudo”)  
> FileUtils.mkdir\_p(dir\_root) unless File.exist?(dir\_root)

No. The system command runs sudo in a shell - a separate executing  
binary  
image - and then throws away its context and returns. The commands then  
run  
without super-user support.

Now what’s the outer problem that makes you need sudo?

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [October 18, 2008, 5:40pm UTC](https://www.ruby-forum.com/t/call-to-sudo/151227/5 "2008-10-18T17:40:33Z")

</div>

> Now what’s the outer problem that makes you need sudo?  
> Create the ‘/usr/local/share/java’ directory if it isn’t already  
> created.

## It was more easy to make:

## dir\_root = /usr/local/share/java FileUtils.mkdir\_p(dir\_root) unless File.exist?(dir\_root)

but I’m supposed that in this case I’ll have to make:

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [October 18, 2008, 6:55pm UTC](https://www.ruby-forum.com/t/call-to-sudo/151227/6 "2008-10-18T18:55:38Z")

</div>

On 18 oct, 16:50, “Phlip” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Kless wrote:
> 
> > system(“sudo mkdir -p #{dir\_root}”)
> 
> First, puts a string that advises the user why they might need to enter  
> their password.
> 
> But shouldn’t you be using a high-level installer for Java itself?

No. I’ve to install anything JAR files in that directory.

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [October 18, 2008, 5:55pm UTC](https://www.ruby-forum.com/t/call-to-sudo/151227/7 "2008-10-18T17:55:48Z")

</div>

Kless wrote:

> system(“sudo mkdir -p #{dir\_root}”)

First, puts a string that advises the user why they might need to enter  
their password.

But shouldn’t you be using a high-level installer for Java itself?
