Forum: Ruby Call to sudo

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kless (Guest)
on 2008-10-18 18:43
(Received via mailing list)
Is possible to call to sudo before of run a ruby statement (for that
can be run that statement)?
James H. (Guest)
on 2008-10-18 18:48
(Received via mailing list)
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
Kless (Guest)
on 2008-10-18 19:18
(Received via mailing list)
On 18 oct, 15:47, James H. <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: ?
Phlip (Guest)
on 2008-10-18 19:25
(Received via mailing list)
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?
Kless (Guest)
on 2008-10-18 19:40
(Received via mailing list)
> 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:
Phlip (Guest)
on 2008-10-18 19:55
(Received via mailing list)
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?
Kless (Guest)
on 2008-10-18 20:55
(Received via mailing list)
On 18 oct, 16:50, "Phlip" <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.
This topic is locked and can not be replied to.