problem writing results to a file

Asked by mike

Hello,
I am having a problem writing test results to a file in a Sikuli script.
...
sts = wait(...)
fp = open("c:Test_results.txt","w")
if sts.getScore() < 0.5 :
  fp.write('Test 1 Failed')
else:
  fp.write('Test 1 Passed')
fp.closed

This fails on oening the file with IOError: (13, 'EACCES', 'c:Test_results.txt')
sts is the match result.
I'm running Windows 7 32 bit as administrator.
Any ideas?
Regards,
Mike

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
mike
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

If you run this in the IDE, the current working directory is c:\Program Files\Sikuli-IDE\ which is specially protected (no matter wether you are admin or not). This access restriction cannot be eliminated running a Sikuli script.

So use a folder that is not specially protected: even c:\ is ok.

Revision history for this message
mike (mike-fletcher) said :
#2

Thanks for the advice.
I tried several variations:
    fp = open('c:\\Test_results.txt','w')
that failed with IOError: (13, 'EACCES', 'c:\\Test_results.txt')

I then tried this (d: is another hard drive)
    fp = open('d:\\Test_results.txt','w')
That succeeded!

So there must be something preventing access to anywhere on c:
Thanks,
Mike

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Uuuups, you are right - might have dreamed on that.

On C: it seems that even the root directory is magically protected.
Just create a folder before running the script and it is possible to write there.

Tip: use raw string r"some-filename-containing\" and you do not need double backslashes.

One more thing:
in your question you wrote
fp.closed
This returns True ore False based upon open state of the stream fp.

If you want to close the file (which is necessary when running in IDE, because otherwise it would not be accessible outside) use
fp.close()

Revision history for this message
mike (mike-fletcher) said :
#4

Thanks - works fine.
Just my luck to stumble on the only two protected directories !!!