Call to sudo


#1

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


#2

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


#3

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: ?


#4

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?


#5

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:


#6

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.


#7

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?