Skip to content Skip to sidebar Skip to footer

Psexec Run Python Script Passed From Host

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\administr

Solution 1:

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"
4

C:\Users\Luke>python -c C:\test\test.py
  File "<string>", line 1
    C:\test\test.py
     ^
SyntaxError: invalid syntax

C:\Users\Luke>echo %ERRORLEVEL%
1

Solution 2:

Was able to access a python script on a shared drive from the remote computer and host, and so by copying to the share from the host and reading from the share on the remote machine i had a suitable workaround (the -i switch is not required).

psexec \\remote_machine_name -u domain\user -p pswrd -i C:/Anaconda/python.exe \\server\share\test\test.py

Related: if you are running on windows and writing to a UNC path from a python script i.e test.py above, helpful path formatting help:

python copy files to a network location on Windows without mapping a drive

Post a Comment for "Psexec Run Python Script Passed From Host"