On Sun, Feb 7, 2010 at 11:02 AM, T <span dir="ltr"><<a href="mailto:misceverything@gmail.com">misceverything@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

I have a script, which runs as a Windows service under the LocalSystem<br>
account, that I wish to have execute some commands.  Specifically, the<br>
program will call plink.exe to create a reverse SSH tunnel.  Right now<br>
I'm using subprocess.Popen to do so.  When I run it interactively via<br>
an admin account, all is well.  However, when I'm running it via<br>
service, no luck.  I'm assuming this is to do with the fact that it's<br>
trying to run under the LocalSystem account, which is failing.  What<br>
would be the best way around this?  Thanks!<br></blockquote><div><br></div><div>I don't know what your specific issue is, but here's some tips for running Python as a service on windows which are not always immediately obvious and can cause failures:</div>

<div><br></div><div>- The search path is screwy: if you are importing a module that happens to be the same name as a dll in system32 (even if this isn't at all a python dll), it can get confused.</div><div>- There is *no* sys.stdout! This is a big one. If any piece of code you're using ever does 'print', the whole thing can crash hard. I replace sys.stdout and sys.stderr with a fake file-like object that catches errors in attempting to .write to the real one and ignores them.</div>

<div><br></div><div>If neither of those two are a problem for you, you need to define "no luck" before anyone will be able to help you. Are there errors in the event viewer? Are you getting an exception that's killing out your service (capture and write to a file with the logging module)? Or is the Popen call being run and returning but just not doing anything (in which case, try capturing output from the command and see if it indicates an error message from plink.exe). Etc.</div>

<div><br></div></div><div name="mailplane_signature">--S</div>