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).My experiments have lead me to the os.exec* collection of methods, and they seem fine, but they don't (as far as I understand them, which isn't very far) allow me to string piped commands or complex collections of switches together in the way that Perl's backticks does. Don't get me wrong, I'm in this to find out how things of this ilk are done in *Python* (if I wanted to know how this was done in Perl, I'd be asking somewhere else), I'm not whining for features. Does Python have a means of doing what I want, or do I construct my command lines in pieces and hand them to os.execl one at a time? Thanks. -- yours, William
signature.asc
Description: Digital signature
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
