I am trying to run a python script on a remote computer via psexec. I am able to connect and run python.exe with the following:
C:\test>psexec \\192.168.X.X -u domain\administrator -p password -i C:\Anaconda\python.exe
The path to python.exe is the path on the remote machine. This opens a python window on the remote machine - all good.
I want to now pass a python script from the host machine to run on the remote. This script is on the host machine in C:\test\test.py. I tried
psexec \\192.168.X.X -u domain\administrator -p password -i "C:\Anaconda\python.exe" -c C:\test\test.py
and get:
C:\Anaconda\python.exe exited on 192.168.X.X with error code 1.
I also tried-c test.py without the full path, and got a similar error. My thought is the remote application cannot find C:\test\test.py. I want to be able to pass the script from the host machine.
Any help is much appreciated. Thanks.
If the .py
extension has been associated with the Python installation on the remote machine, you may be able to run your Python script by simply removing the Python executable from the command line:
psexec \\192.168.X.X -u domain\administrator -p password -i -c C:\test\test.py
Please note that I have not tried this as I don't presently have access to a remote machine, so I can't guarantee that it will work.
The line
psexec \\192.168.X.X -u domain\administrator -p password -i "C:\Anaconda\python.exe" -c C:\test\test.py
may be trying to run the command "C:\Anaconda\python.exe" -c C:\test\test.py
on the remote machine. In other words, Python may be interpreting the -c
switch, rather than PsExec. The Python switch -c
specifies some Python code to run, and of course a filename is not valid Python code:
C:\Users\Luke>python -c "print 2 + 2"
4C:\Users\Luke>python -c C:\test\test.pyFile "<string>", line 1C:\test\test.py^
SyntaxError: invalid syntaxC:\Users\Luke>echo %ERRORLEVEL%
1