Re: [Tutor] Fwd: Executing a command from a specific directory

2009-09-16 Thread Sander Sweers
On Wed, 2009-09-16 at 18:03 +0530, Ansuman Dash wrote:
> if "Request timed out.." not in a:
> print("Ping is not successful.")
> pLogger.info("Ping is not successful.")

This will check for the string "Request timed out.." is NOT in a. Now
when the ping is successfull the string will not be in a. I suspect you
are looking for the logic being reversed so remove the not.

Greets
Sander


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Executing a command from a specific directory

2009-09-16 Thread Ansuman Dash
Hi,

Thank you very much for the quick response.

Code is working fine.

Now I am trying to validate that the command is executed successfully.
I have written following script to validate the log file which is created
after running the command.


if os.access("C:/Python25/Own.log", os.F_OK):
f = open("C:/Python25/Own.log")
time.sleep(30)
try:
for line in f.readlines():
a=line

if "Request timed out.." not in a:
print("Ping is not successful.")
pLogger.info("Ping is not successful.")
else:
print ("Ping is successful.")
pLogger.info("Ping is successful.")

finally:
f.close()
else:
pLogger.info("File doesn't exist")
=

But it is not working, even if ping is successfully it is printing "Ping is
not successful.". Can you please point out where I am making mistake.

Thanks,
AD


On Wed, Sep 16, 2009 at 12:55 PM, Patrick Sabin
wrote:

> Ansuman Dash schrieb:
>
>
>> Hello Everybody,
>>
>> In Python scripting, how can I execute a command (which can be run from
>> spcific directory) and then retrieve the result (after executing the command
>> it give the command is executed successfull or not), so that I can validate
>> it.
>>
>> Thanks,
>> AD
>>
>>
>>
> import os
> import subprocess
>
> os.chdir('/your/directory')
> p = subprocess.Popen("ls -l", shell=True, stdout=subprocess.PIPE)
> out = p.stdout.read()
> print out
>
> - Patrick
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Executing a command from a specific directory

2009-09-16 Thread Patrick Sabin

Ansuman Dash schrieb:


Hello Everybody,

In Python scripting, how can I execute a command (which can be run from 
spcific directory) and then retrieve the result (after executing the 
command it give the command is executed successfull or not), so that I 
can validate it.


Thanks,
AD




import os
import subprocess

os.chdir('/your/directory')
p = subprocess.Popen("ls -l", shell=True, stdout=subprocess.PIPE)
out = p.stdout.read()
print out

- Patrick

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor