Re: [Vala] problem using sleep

a a wrote:
I'd like to sleep for X minutes and then run a command as root.
I've tried this with no success:
Process.spawn_command_line_async("sleep "+time_min+"m ; gksudo
(in the terminal it works)

How should I do it?

Thanks :)


you can't concatenate commands as you would do it in a shell.

If your program is running a GLib main loop (e.g. a GTK+ program or if
you're using GLib.MainLoop directly) then you can set a timeout:

int time_min = 5;

Timeout.add (time_min * 1000 * 60, () => {
        try {
                Process.spawn_command_line_async ("gksudo '/etc/acpi/'");
        } catch (Error e) {
                stderr.printf ("%s\n", e.message);
        return false;

If you're returning 'true' instead of 'false' the process will be
spawned repeatedly every x minutes.

Best regards,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]