turning a python script to windows service
jeff at ccvcorp.com
Wed Mar 27 20:10:26 CET 2002
> 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.
> 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'
output = os.popen(cmdline)
for line in output:
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.
More information about the Python-list