run multiple non interacticve root commands

Post

Posted
Rating:
#1 (In Topic #1512)
Banned
 A class to let your program start an internal process as root and use multiple commands.

password is held in memory and used with sudo and Process.Expect() when run

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Interesting! Will try it as soon as we have a need, which may be sooner than I'd like.

(Linear Programming job is progressing leaps and bounds. Pity I own none of it  :(  I'll just have to remember how we did it for personal use one day.)
It looks like what you did there might solve installs for the thousands of students that are going to use it.  Would you believe hundreds? How about a few.

b

Online now: No Back to the top

Post

Posted
Rating:
#3
Banned
if it helps 1 person i'll be happy :)

It's helped me.
I use the same class in my VBox-image mounter program. VirtualBox image mounter - Gambas ONE

It's a Static class,
I just use RootCommand(sCommand) where it needs it (to mount/unmount the vbox drives) and it only asks for password the first time.
Online now: No Back to the top

Post

Posted
Rating:
#4
Banned
 I have found other ways to do this also using bash internally.

I have used either a hidden TerminalView or just Exec/Shell process to run bash as su.
hBashProcess = Shell "pkexec env XAUTHORITY=" & Env["XAUTHORITY"] & " DISPLAY=" & Env["DISPLAY"] & " bash" For Input Output As "Proc"

Then use Write/Print to send the commands through the bash process.
Print #hBashProcess, sCommand

It works but has limitations with not knowing if the commands have finished running as Process.State relates to bash not the command it's running.
Also you have to exit bash before program closes.

The above RootCommander.class is better as it uses Process.Expect() on commands run directly (using sudo) So you can Check RootCommand.Process.State to see if the individual commands have finished running or not before allowing more.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly leads the usergroup ‘GambOS Contributor’
gbWilly is in the usergroup ‘Blogger’

BruceSteers said

A class to let your program start an internal process as root and use multiple commands.

password is held in memory and used with sudo and Process.Expect() when run
Now we're talking  :lol:
I might wanna have a look at this  ;)

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
ercoupeflyer is in the usergroup ‘Regular’
ercoupeflyer is in the usergroup ‘Blogger’
My take on this can be found in the Software farm as PowerShell 1.1.1, there was an older version that had a propensity to remove the project directory when closed after an error, which happened after a recent update to sudo.. umm

It starts a background process and pops up a graphic user password request. after which it allows the application to send requests to be executed, to the running shell, which then returns the output from the command. as a series of lines, as well as the returned exit code from the executed command. Requests may be queued in the pipe to the root shell.

The received data is asynchronous, using events to deliver info to the users app, errors are also delivered asynchronously.

Don't know if this is useful. but has been for me.

Brian
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
ercoupeflyer is in the usergroup ‘Regular’
ercoupeflyer is in the usergroup ‘Blogger’
Looking at the code of PowerShell, I decided to update it such that in now also generates a completed event, when the command exits.
It returns , the exit code and the originating command in the event.

I updated the version on the software farm…
As always I am always over thinking thing!! lol
Online now: No Back to the top
1 guest and 0 members have just viewed this.