Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

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:	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

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...