[Tutor] Executing a command from a specific directory
Ansuman Dash
ansuman.dash at gmail.com
Thu Sep 17 11:47:45 CEST 2009
Hi,
I modified my code little bit and it is working fine now,
=====================================================
if os.access("C:/Python25/Own.log", os.F_OK):
f = open("C:/Python25/Own.log")
time.sleep(30)
try:
line = f.readlines()
a = string.join(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 I have question to ask, as you can see I am using "time.sleep(30)" to
make my code wait. Is there any other way I can write my script to resolve
synchronization issues.
Thanks,
AD
On Thu, Sep 17, 2009 at 12:13 AM, Steve Willoughby <steve at alchemy.com>wrote:
> > Ansuman Dash wrote:
> > >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.
>
> Notice what's happening here:
>
> > > for line in f.readlines():
> > > a=line
>
> This sets a to EACH line from the file, overwriting
> the previous one. What you end up with after that
> executes is a holding the LAST line in the file.
>
> > > if "Request timed out.." not in a:
> > > print("Ping is not successful.")
> > > pLogger.info("Ping is not successful.")
>
> Also... this looks backwards. If "Request timed out.." is NOT found
> then the ping was NOT successful?
>
> --
> Steve Willoughby | Using billion-dollar satellites
> steve at alchemy.com | to hunt for Tupperware.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090917/3b788678/attachment.htm>
More information about the Tutor
mailing list