Re: [Vala] problem using sleep



I have a small question about this code:

If I add some code below your example would it be executed before
"Process.spawn_command_line_async" ? I mean, the program will go on and only
"Process.spawn_command_line_ async" is delayed  ?

If so, how can I delay the whole program ?

Sorry to interrupt and thanks...

On Sat, Oct 10, 2009 at 6:38 PM, Frederik <scumm_fredo gmx net> wrote:

a a wrote:
Hello.
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
'/etc/acpi/hibernate.sh'");
(in the terminal it works)

How should I do it?

Thanks :)

Hi,

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/hibernate.sh'");
       } 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,

Frederik
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list



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