On Thu, 2005-05-12 at 13:37 -0400, William O'Higgins wrote:
> I am trying to learn Python by translating some of my Perl scripts.  One
> thing that is eluding me is assigning the results of system calls to
> variables.  Here's what I want to do in Perl:
>     
>     $isxrunning = `ps -C startx | grep "startx"`;
>     
>     if ($isxrunning =~ "startx") {
>         do something;
>     } else {
>         do something else;
>     }
>             
> It is a simple check to see if the X server is running (this is
> inelegant, but it works - if you have a better way, I'd love to know
> about it, but I would like to be able to do things like this in Python -
> so I might better write scripts with it).
> ...
(This is off topic! Sorry.)

Why using âps -C startx | grep "startx"â?  Why not âps h -C startxâ[1]?
Even better, why not âpidof startxâ?

As for another way to check for X, did you try checking for the lock
file? (Usually in â/tmp/.X0-lockâ)  Combined with checking the $DISPLAY
environment variable, this is a much better and elegant solution in my
not-so-experienced opinion.

Notes:
     1. This probably wont work with FreeBSD (and all other *BSD(s) in
        that matter), instead, try the â--no-headersâ option.  See the
        manual page for âpsâ.

Ziyad.
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to