Python: Run interactive command line window on remote computer (with psexec)

79 Views Asked by At

What I want to do:

I have a python app and in the background, I want to run a separate process that connects to a remote computer with psexec.

While the app is running, the psexec process is still open. Based on certain selections and actions the user will make in the app, I will need to do different things on the remote computer.

In order to perform these actions on the remote computer, I need to run different commands within the opened psexec computer (ie: run an application. Delete/Copy files, etc)

What I have so far

So far I am able to run psexec from a python script with a command like the following:

psexec "\\server-name" -u "username" -p "password" [some cmd]

Here, [some cmd] can be any number of commands. But it has to be all at once.

Next I create a sub process:

subprocess.Popen([psexec cmd], shell=True)

When I do this. Now this sub process runs in the 'background' so to speak.

Where I am Stuck

Now. I have my subprocess open (which is a connection to the remote server).

How can I keep running different commands on the remote computer?

In other words. How do I keep accessing the psexec command line?

I want to basically do the following:

  • proc = subprocess.Popen([psexec cmd], shell=True)
  • proc.runCommand(command 1) #command1 runs on remote computer
  • user does some things on the app
  • proc.runCommand(command 2) #command2 runs on remote computer
  • user does some more things on the app
  • proc.runCommand(command 3) . . .
  • user exits app -> proc.kill()
0

There are 0 best solutions below