[SOLVED] Sending System Command
Posted
#1
(In Topic #925)
Enthusiast

I have a question
Can I use Reboot and Shutdown from Gambas?
I ask as I have a Program that take over my system and it stays in FULL screen (and the terminal only has a 32 keyboard attached)
I have a Menu with in my software that shows the following Menu
1. Exit PoS
2. Reboot PoS
3. Shutdown PoS
how do I reboot a system from with in Gambas?
I tried
Shell "Reboot now"
but it says Reboot not found (as it ha to be down as a SU User)
any recommendation is most welcomed.
Posted
Guru

AndyGable said
Hi All,
I have a question
Can I use Reboot and Shutdown from Gambas?
I ask as I have a Program that take over my system and it stays in FULL screen (and the terminal only has a 32 keyboard attached)
I have a Menu with in my software that shows the following Menu
1. Exit PoS
2. Reboot PoS
3. Shutdown PoS
how do I reboot a system from with in Gambas?
I tried
Shell "Reboot now"
but it says Reboot not found (as it ha to be down as a SU User)
any recommendation is most welcomed.
i have commands reboot and shutdown in my system
Ps. not a lot of linux commands have capital letters in them
also be sure to not exit the application to soon before its got a chance to run the shutdown/reboot command as you can kill the process before it starts.
Posted
Enthusiast

BruceSteers said
AndyGable said
Hi All,
I have a question
Can I use Reboot and Shutdown from Gambas?
I ask as I have a Program that take over my system and it stays in FULL screen (and the terminal only has a 32 keyboard attached)
I have a Menu with in my software that shows the following Menu
1. Exit PoS
2. Reboot PoS
3. Shutdown PoS
how do I reboot a system from with in Gambas?
I tried
Shell "Reboot now"
but it says Reboot not found (as it ha to be down as a SU User)
any recommendation is most welcomed.
i have commands reboot and shutdown in my system
Ps. not a lot of linux commands have capital letters in them
also be sure to not exit the application to soon before its got a chance to run the shutdown/reboot command as you can kill the process before it starts.
I have this printed in the console window "/bin/sh: 1: reboot: not found
on my Debain machine I have to use SU before I can run reboot is that why I am having issues with this command as well?
Posted
Guru

or
Code (gambas)
or DBus..
Code (gambas)
- Try DBus["org.gnome.SessionManager"]["/org/gnome/SessionManager", "org.gnome.SessionManager"].Reboot()
Posted
Guru

Check out the Sysmenu file at
.src/SysMenu/fMenu.class · main · Bruce Steers / Desktop-ish · GitLab
It tries a few methods to shutdown/reboot/etc.
Posted
Guru

/usr/sbin/reboot
/usr/sbin/shutdown
Being in sbin they are sudo only
if you move them to /usr/bin they will work
sudo mv /usr/sbin/reboot /usr/bin/reboot
sudo mv /usr/sbin/shutdown /usr/bin/shutdown
Posted
Guru

dbus via shell.. (tested on debian11/MATE, needs dbus-send installed)
Code (gambas)
- Shell "dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Reboot boolean:true"
Code (gambas)
- Shell "dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.PowerOff boolean:true"
Gambas commands using gb.dbus component…
Code (gambas)
- DBus["system://org.freedesktop.login1"]["/org/freedesktop/login1", "org.freedesktop.login1.Manager"].Reboot(True)
Code (gambas)
- DBus["system://org.freedesktop.login1"]["/org/freedesktop/login1", "org.freedesktop.login1.Manager"].PowerOff(True)
Posted
Enthusiast

BruceSteers said
if you don't want to move the binaries then try dbus
dbus via shell.. (tested on debian11/MATE, needs dbus-send installed)Code (gambas)
Shell "dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Reboot boolean:true"Code (gambas)
Shell "dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.PowerOff boolean:true"
Gambas commands using gb.dbus component…Code (gambas)
DBus["system://org.freedesktop.login1"]["/org/freedesktop/login1", "org.freedesktop.login1.Manager"].Reboot(True)Code (gambas)
DBus["system://org.freedesktop.login1"]["/org/freedesktop/login1", "org.freedesktop.login1.Manager"].PowerOff(True)
Posted
Guru

if gnome exists..
DBus["session://org.gnome.SessionManager"]["/org/gnome/SessionManager", "org.gnome.SessionManager"].RequestShutdown()
DBus["session://org.gnome.SessionManager"]["/org/gnome/SessionManager", "org.gnome.SessionManager"].RequestReboot()
I try them all to try to make them work on any system. not all systems support freedesktop.login1 method …
this tries gnome.sessionmanager / kde.sessionmanager and freedesktop.login1 methods and also checks for cancelled request…
Note some shutdown methods will just shutdown while other will pop up the shutdown message window that offers options.
Code (gambas)
- Try DBus["org.gnome.SessionManager"]["/org/gnome/SessionManager", "org.gnome.SessionManager"].RequestShutdown()
- DBus["session://org.kde.Shutdown"]["/Shutdown", "org.kde.Shutdown"].logoutAndShutdown()
Download the Gambas DBus Explorer from the farm to see what DBus has to offer
Or better still use my version.
I modified the DBus explorer to copy almost usable command text when double clicking an item.
so if i doubleclick the gnome session manager CanShutdown item i get this copied to my clipboard..
DBus["session://org.gnome.SessionManager"]["/org/gnome/SessionManager", "org.gnome.SessionManager"].CanShutdown() ' As Boolean
EDIT: oops forgot to attach the explorer
1 guest and 0 members have just viewed this.



