newbie script

A

ataraxia2500

I wanna do a script that launch a programm xyz and relaunch xyz if it
crashes. what kind of module do I need for such a task?

thanx in advance
 
E

Ed

If you're UNIX based:

os.system('xyz') will return the exit status of your program xyz.
More importantly for you, it will return!

So try an (ugly) loop like:

import os
while 1:
os.system('xyz')


-Ed
I wanna do a script that launch a programm xyz and relaunch xyz if it
crashes. what kind of module do I need for such a task?

--
Andrew Edmondson
Senior Analyst
QinetiQ Malvern
Tel: +44 1684 897433
Mobile: +44 794 1103773
PGP Key:
http://search.keyserver.net:11371/pks/lookup?op=get&search=0xCEE814DC
PGP Fingerprint: 7B32 4D1E AC4F 29E2 9EAA 9550 1A3D BBA4 CEE8 14DC
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

ataraxia2500 said:
I wanna do a script that launch a programm xyz and relaunch xyz if it
crashes. what kind of module do I need for such a task?

Something like this:

import os
while 1:
os.system("j:/UT2003/System/UT2003.exe")

os.system executes a program and waits, until the program is terminated.
But there's no way to know wether the program was terminated
deliberately or wether it crashed.

-- Gerhard
 
A

ataraxia2500

ok thanx I'm on linux, what I want basically is the script to launch xyz
and then check if it's running using os.system('xyz'), and if it's not
running I want the script to relaunch xyz. So could u tell me please also
how to launch or relaunch a programme please :)
 
E

Ed

os.system('xyz') runs in a shell, and when it exits returns its exit status.
e.g.:
a=os.system('ls bogus_directory')
if bogus_directory exists then 'a' = 0, and if not 'a' = 1.

while 1:
os.system('xyz')

will run the program xyz, and as soon as xyz exits it will run it again -
and so on.

-Ed
ok thanx I'm on linux, what I want basically is the script to launch xyz
and then check if it's running using os.system('xyz'), and if it's not
running I want the script to relaunch xyz. So could u tell me please also
how to launch or relaunch a programme please :)

--
##############################################################################
Andrew Edmondson
PGP Key:
http://search.keyserver.net:11371/pks/lookup?op=get&search=0xCEE814DC
PGP Fingerprint: 7B32 4D1E AC4F 29E2 9EAA 9550 1A3D BBA4 CEE8 14DC
 
E

Eric Brunel

Gerhard said:
Something like this:

import os
while 1:
os.system("j:/UT2003/System/UT2003.exe")

os.system executes a program and waits, until the program is terminated.
But there's no way to know wether the program was terminated
deliberately or wether it crashed.

There is a way. Quoting the documentation for the os module for os.system:

The return value is the exit status of the process encoded in the format
specified for wait(), except on Windows 95 and 98, where it is always 0.

And for os.wait:

exit status indication: a 16-bit number, whose low byte is the signal number
that killed the process, and whose high byte is the exit status (if the signal
number is zero); the high bit of the low byte is set if a core file was produced.

According to my experience, it is also better to test for None in the return
value, since it seems to happen when everything is OK. So, doing:

while 1:
exitStatus = os.system("command...")
if exitStatus is None: break
if exitStatus & 0xFF == 0: break

should do the trick.

HTH
 
A

ataraxia2500

hey Ed,
I get that weird error when I tried to run the little loop, this is what it
says:

sys:1: DeprecationWarning: Non-ASCII character '\xa0' in file myloop.py on
line 3, but no encoding declared; see http://www.python.org/peps
pep-0263.html for details
File "myloop", line 3
        os.system('/home/joe/src/myprog/myprog')
^
SyntaxError: invalid syntax

does it mean anything to you?

thanx in advance
 
A

Alex Martelli

ataraxia2500 said:
hey Ed,
I get that weird error when I tried to run the little loop, this is what
it says:

sys:1: DeprecationWarning: Non-ASCII character '\xa0' in file myloop.py on
line 3, but no encoding declared; see http://www.python.org/peps
pep-0263.html for details
File "myloop", line 3
os.system('/home/joe/src/myprog/myprog')
^
SyntaxError: invalid syntax

does it mean anything to you?

Sure! You have a weird character, of hex code A0, somewhere on your
line 3. How it got there, I dunno. Anyway, what you need to do is
remove it -- a good editor should be able to show you exactly where
it is, otherwise just use a small Python script to find that out.


Alex
 
A

ataraxia2500

<posted & mailed>

Alex said:
Sure! You have a weird character, of hex code A0, somewhere on your
line 3. How it got there, I dunno. Anyway, what you need to do is
remove it -- a good editor should be able to show you exactly where
it is, otherwise just use a small Python script to find that out.


Alex
this is my line 3: os.system('/home/joe/src/myprog/myprog')

I even tried os.system('ls /') as line 3 and I still sot the same ascii
error;
 
P

Peter Otten

ataraxia2500 said:
I get that weird error when I tried to run the little loop, this is what
it says:

sys:1: DeprecationWarning: Non-ASCII character '\xa0' in file myloop.py on
line 3, but no encoding declared; see http://www.python.org/peps
pep-0263.html for details
File "myloop", line 3
os.system('/home/joe/src/myprog/myprog')
^
SyntaxError: invalid syntax

does it mean anything to you?


The whitespace before os.system() consists of '\xa0' characters, no idea
why.

However, I have noticed that when I copy and paste from KNode 7.2 using
Strg+C/Strg+V instead of the middle mouse button, all '\xa0' are magically
converted back to old '\x20' space characters.

Peter
 
A

ataraxia2500

Peter said:
The whitespace before os.system() consists of '\xa0' characters, no idea
why.

However, I have noticed that when I copy and paste from KNode 7.2 using
Strg+C/Strg+V instead of the middle mouse button, all '\xa0' are magically
converted back to old '\x20' space characters.

Peter
what editor do u use? I'm using kedit and kwrite
 
A

ataraxia2500

Peter said:
The whitespace before os.system() consists of '\xa0' characters, no idea
why.

However, I have noticed that when I copy and paste from KNode 7.2 using
Strg+C/Strg+V instead of the middle mouse button, all '\xa0' are magically
converted back to old '\x20' space characters.

Peter
ok thanx that was the problem, I use knode from CVS and when I did a Ctrl+C
it asked me what encoding I wanted, how neat! but I had no idea which one
to chose, after two failure I decided to type it by myself and it worked :)
 
P

Peter Otten

Peter said:
However, I have noticed that when I copy and paste from KNode 7.2 using
Strg+C/Strg+V instead of the middle mouse button, all '\xa0' are magically
converted back to old '\x20' space characters.

Sorry, I have tried to reproduce the behaviour stated above and was not able
to reproduce it. So whatever I did differently, it was not the copy and
paste method :(

Peter
 
P

Peter Otten

Peter said:
Sorry, I have tried to reproduce the behaviour stated above and was not
able to reproduce it. So whatever I did differently, it was not the copy
and paste method :(

The version that worked was copied from the article *source* window while
the '\xa0'-polluted variant came from the article *viewer*.

(hope I'm having it right this time and KNode is not fooling me again...)

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top