Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:	est>psexec \192.168.X.X -u domainadministrator -p password -i C:Anacondapython.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: est est.py. I tried

psexec \192.168.X.X -u domainadministrator -p password -i "C:Anacondapython.exe" -c C:	est	est.py

and get:

C:Anacondapython.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: est est.py. I want to be able to pass the script from the host machine.

Any help is much appreciated. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
363 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 domainadministrator -p password -i -c C:	est	est.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 domainadministrator -p password -i "C:Anacondapython.exe" -c C:	est	est.py

may be trying to run the command "C:Anacondapython.exe" -c C: est est.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:UsersLuke>python -c "print 2 + 2"
4

C:UsersLuke>python -c C:	est	est.py
  File "<string>", line 1
    C:	est	est.py
     ^
SyntaxError: invalid syntax

C:UsersLuke>echo %ERRORLEVEL%
1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...