Discussion:
Execute batch script on remote computer
Tim Golden
2006-02-13 16:13:18 UTC
Permalink
[py]

| I am trying to execute a batch script on a remote computer.
|
| The batch script looks like:
|
| @echo off
| start c:\python24\python.exe c:\a_script.py
|
|
| Here's the setup:
| Computer A (my computer), Computer B (the remote computer).
|
| So I map "W:" to Computer B and then copy the batch script to Computer
| B. Then from within Python on Computer A I run:
| import subprocess
| subprocess.Popen("W:\\foo.bat")
|
| However, when it runs it says it can't find c:\a_script.py. It seems
| to be trying to look
| at Computer A, not Computer B. How can I do this?

You're confusing a couple of things here. One is a
drive mapping, which presents the *filesystem* of a
remote computer as though it were local. The other
is a remote procedure call, which presents the
*processor* (and environment etc.) of a remote
computer as though it were local.

What you're doing has the effect of running a
remote *file* on a local *processor*.

You could run a remote script -- on the *remote*
processor -- under vanilla Windows using WMI, and
possibly using some other DCOM-based technology, such
as WSH. But you'd run into some security / environment
issues depending on just what your remote script was
trying to do.

You could also -- if you were prepared to invest in
some more software infrastructure -- employ Pyro
(http://pyro.sf.net), Corba, XML-RPC or any one of
several other RPC-type technologies.

Are you even more confused now than you were when
I started? ;)

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
py
2006-02-13 15:53:50 UTC
Permalink
I am trying to execute a batch script on a remote computer.

The batch script looks like:

@echo off
start c:\python24\python.exe c:\a_script.py


Here's the setup:
Computer A (my computer), Computer B (the remote computer).

So I map "W:" to Computer B and then copy the batch script to Computer
B. Then from within Python on Computer A I run:
import subprocess
subprocess.Popen("W:\\foo.bat")

However, when it runs it says it can't find c:\a_script.py. It seems
to be trying to look
at Computer A, not Computer B. How can I do this?

Thanks
py
2006-02-13 16:23:36 UTC
Permalink
WMI will work, i can create a new Win32_Process. XML_RCP would be
nice, but probably to much for what i need.

thanks.
Tim Golden
2006-02-13 17:13:37 UTC
Permalink
[py]

(re running remote processes)

| WMI will work, i can create a new Win32_Process.

OK, but remember that the process won't interact with the
desktop on the remote machine -- which may well be what you
want -- and also that the environment will likely be different,
unless you're connecting as a specific user (and even then
I'm not sure!) So make sure that your Python paths etc.
will work, and that the user the process is running under
has sufficient security to do whatever it needs.

| XML_RCP would be nice, but probably to much for what i need.

XML-RPC is quite lightweight, but requires a running server
on the remote machine. (Not a big deal, but still more than
using the already-there WMI).

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
Continue reading on narkive:
Loading...