turning a python script to windows service

Jeff Shannon jeff at ccvcorp.com
Wed Mar 27 14:10:26 EST 2002


kedai wrote:

> is there anything special that i need to do if i wanted to do more
> stuff; for example, i tried copying files but nothing was copied.
>
> snippet:
> os.system('copy file filedst') #instead of print statement

This *should* work if you specify the fully qualified pathnames for the files involved.  One of the
things to watch out for with services (in my *very* limited experience), is that it's not safe to assume
much of anything about your environment (including current working directory, etc).  If you want to test
it, I'd change the above statement to this:

cmdline = 'copy file filedst'
print cmdline
output = os.popen(cmdline)
for line in output:
    print line

This will, first off, print (to the trace window) the command that you're intending to run. Then it runs
the command in a pipe, giving you the output of that command, which is printed to the trace window.  This
should help you to see what, if anything, is happening -- if you're getting an error from Windows for
that command, this should display that error in the trace window.

Of course, for small files, I'd be more likely to copy them using this:

    open(filedst, "wb").write( open(file, "rb").read() )

rather than using the os.system() call.

Jeff Shannon
Technician/Programmer
Credit International






More information about the Python-list mailing list