psexec run python script passed from host

2024/10/6 0:33:47

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.

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 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
https://en.xdnf.cn/q/119010.html

Related Q&A

TypeError: main() missing 1 required positional argument: self

My code and error is below and I was trying to understand why I am getting the error and how to fix it. I tried this without self and got another error TypeError: load_data() takes 0 positional argumen…

Python not calling external program

I am having problems with a python program that I wrote. It is actually plpython3u. I am running the program as a Trigger from postgres. I am pretty sure the trigger part works. My test python prog…

Selenium: How do I retry browser/URL when ValueError(No tables found)

I have a code that scrapes oddsportal website. Sometimes while scraping, I get ValueError("No tables found") and when I manually refresh browser, page loads. How do I do it via code? My code…

For loop for web scraping in python

I have a small project working on web-scraping Google search with a list of keywords. I have built a nested For loop for scraping the search results. The problem is that a for loop for searching keywor…

operation on a variable inside a class in python

Im new with oop and python. Ive been trying to do a simple thing: there is class called Foo(),it contains a variable called x which is initially set to zero.>>>a = Foo() >>>a.x >&g…

Print several sentences with different colors

Im trying to print several sentences with different colors, but it wont work, I only got 2 colors, the normal blue and this redimport sys from colorama import init, AnsiToWin32stream = AnsiToWin32(sys.…

Discord bot to send a random image from the chosen file

I am making a discord bot that randomly chooses an image (images) which is in the same directory (Cats) as the python file(cats.py). This is what my code looks like right now: Cats = os.path.join(os.pa…

pytest - patched method of a class does not return the mock value

My code is fairly simple but i dont understand what is going on :class MyDb :def some_func( arg ) :....while my test code is :@mock.patch(mypkg.mydb) @pytest.mark.parametrize( func_dummy_value ) :( [ {…

New instance of toplevel classes make overlapping widgets

Im generally new to python and tkinter. Ive been programming maybe about a year or so, and Ive just started to try to make each tkinter toplevel window its own class because Ive heard that its the righ…

Regex End of Line and Specific Chracters

So Im writing a Python program that reads lines of serial data, and compares them to a dictionary of line codes to figure out which specific lines are being transmitted. I am attempting to use a Regul…