I am trying to launch a PuTTY window that establishes a serial connection, and then have the main cmd window (the one that launched my Python script) control the PuTTY window. The PuTTY window will still be open and showing everything, but I want to disable the stdin on it and just have it get the input from the cmd shell.
So I have it successfully launching the PuTTY window, just cant seem to pipe my outputs and inputs like I want. Any help would be greatly appreciated!
Code for launching PuTTY window:
pty=subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
PuTTY is a GUI application. It is not designed for automation.
For automation, use the Plink, PuTTY command-line utility. It is a console application, so it reads commands from its standard-input.
See:
Using the command-line connection tool Plink.
Run Unix commands using PuTTY in C#
PuTTY (note case) is a GUI program and has nothing what so ever to do with cmd prompts.
I use PuTTY all day and out of a lot of people (my coy has 175,000 employees but most wouldn't use PuTTY) I'm the only one that automates it. I use VBScript sendkeys bound to hotkeys in windows shortcuts (must be on desktop or start menu).
PuTTY does have a command line version with a similar name, but I've not used it.
Related
I tried to do this with WMI, but interactive processes cannot be started with it (as stated in Microsoft documentation). I see processes in task manager, but windows do not show.
I tried with Paramiko, same thing. Process visible in task manager, but no window appears (notepad for example).
I tried with PsExec, but the only case a window appears on the remote machine, is when you specify -i and it does not show normally, only through a message box saying something like "a message arrived do you want to see it".
Do you know a way to start a program remotely, and have its interface behave like it would if you manually started it?
Thanks.
Normally the (SSH) servers run as a Windows service.
Window services run in a separate Windows session (google for "Session 0 isolation"). They cannot access interactive (user) Windows sessions.
Also note that there can be multiple user sessions (multiple logged in users) in Windows. How would the SSH server know, what user session to display the GUI on (even if it could)?
The message you are getting is thanks to the "Interactive Services Detection" service that detects that a service is trying to show a GUI on an invisible Session 0 and allows you to replicate the GUI on the user session.
You can run the SSH server in an interactive Windows session, instead as a service. It has its limitations though.
In general, all this (running GUI application on Windows remotely through SSH) does not look like a good idea to me.
Also this question is more about a specific SSH server, rather that about an SSH client you are using. So you you include details about your SSH server, you can get better answers.
ok i found a way. With subprocess schtasks( the windows task scheduler). For whatever reason, when i launch a remote process with it , it starts as if i had clicked myself on the exe. For it to start with no delay, creating the task to an old date like 2012 with schtasks /Create /F and running the then named task with schtasks /Run will do the trick
I need to execute python script on remote server (access through puTTY), but I don't have a stable Internet connection, and every time I execute the script I get problems after several minutes due to my Internet getting disconnected.
How do I remotely execute the script without being connected to server?
(e.g. I connect to server, run script, and can logout while executing)
You can use a Linux Screen, it opens a background terminal and keeps a shell active even through network disruptions.
Open the screen typing in your terminal $ screen and execute there your script, even if you lose connection it won't kill the process.
Here you will find a well explained How to for this program. I use it for my regular day working on remote.
try this
nohup your_script >/dev/null 2>&1 &
program will be running in background
I have an external server that I can SSH into. It runs bots on reddit.
Whenever I close the terminal window the bot is running in, the process stops, which means the bot stops as well.
I've tried using
nohup python mybot.py
but it doesn't work - when I close the window and check the processes (ps -e), python does not show up. Are there any alternatives to nohup? Ideally, that print the output to the terminal, instead of an external file.
Have you considered using tmux/screen? They have lots of features and can help you detach a terminal and re-attach to it at a later date without disrupting the running process.
I am using Python and wxpython for gui. I am trying to connect ssh tunnel. After connecting to ssh, wants a new terminal to open and have to continue my operation in local machine. How to achieve this?
I tried subprocess, pexpect and paramiko, but all are capable to connect to ssh but not open the new teminal
Below my code is there which I tried with pexpect:
import time
import sys
import pexpect
c = pexpect.spawn("ssh -Y -L xxxx:localhost:xxxx user # host.com")
time.sleep(0.1)
c.expect("[pP]aasword")
c.sendline("xxxxxx")
time.sleep(0.2)
c.interact()
c.pexpect([user#host.com~]$)
# here after its connects to ssh then command wont be executed
c.sendline("xfce4-terminal")
On 24/04/2013
I am able to open new terminal but what happens is when the new terminal will open controls from gui doesn't go there. Any help?
Opening a new local terminal and connecting an existing process in to it is a little complicated. There are at least three approaches:
Open the terminal before you start connecting, and run all the code that tries to establish the connection from within it. This is simplest. The main drawback is that the terminal will appear even if the connection fails, which might be what you want to avoid.
Run the connection attempt with a session of tmux or screen and if you detect that it succeeded then reattach that session in to a new terminal.
Make your Python program provide a pty that the terminal can attach to - your program will need to hang around and pass input and output between the remote connection and the pty.
I'm using this tool to set up a ssh server on Windows. I'm trying to open the standard Python shell through a remote ssh connection but I simply can't get it to work. If I type 'python' in my ssh command line nothing happens, it just seems to wait for more input. My server machine however, shows a new python process running after I do this.
Running scripts works fine, though.
Do I need to use another Python shell, some other ssh server, some different configs?
Thanks
My guess is that Python is not recognising the stdin on the SSH shell as a terminal. I don't know why that would be.
However, try running "python -i" to overcome it.
The problem is probably that you're running the Windows Python executable, which expects a Windows console environment to run in, over a channel which doesn't support the features of Windows console. You might find Andy Koppe's conin to be useful.