0

So I am trying to do following:

  1. I have Cygwin enabled with screen and ssh daemon in Windows 7.
  2. I create a new screen using the command screen -dmS "my_screen" on my Windows machine.
  3. I ssh to the Windows machine from my Linux machine.
  4. I attach to it from my unix machine using screen -d -r my_screen
  5. Now I try to launch a Windows application, for example notepad.exe.

Now I want to a automate this using Python. The objective is to just manually ssh to Windows and then run a Python script which will do the above steps. I have written the following script but it is not working:

import shlex
import os
import time
import subprocess

cmdString = "screen -d -r default_screen"

cmdArgs=shlex.split(cmdString)

p=subprocess.Popen(cmdArgs)

cmds = "./notepad.exe"

cArgs=shlex.split(cmds)

pp=subprocess.Popen(cArgs)

This is not working. :( Basically to get the screen I will probably need to import pty package or tty. But pty & tty are not supported in Windows. I am able to attach to the newly created screen but then attempt to launch the Windows program like notepad for example fails. It hangs and the windows GUI is not launched as it would when down manually.

I am still exploring this but I will appreciate it if someone can point me to the right way to do it.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • `This is not working. :(` tells us next to nothing about the issues you are seeing ... – Joran Beasley Jul 30 '14 at 00:25
  • Basically to get the screen I will probably need to import pty package or tty. But pty does not exists in windows. I am able to attach to the newly created screen but then attempt to launch the windows program like notepad for example fails. It hangs and the windows GUI is not launched as it would when down manually. – internalerror404 Jul 30 '14 at 00:37
  • From editing the post just now I noticed one typo in the code (`subporcess` instead of `subprocess`) that would've meant that `import` would've failed when that code was run. It doesn't sound like that happened in your case, since it sounds like `screen` was run, which suggests the code you were running was not exactly what was pasted in. – khampson Jul 30 '14 at 01:33
  • Thanks Ken. No, its not failing because of that. I am just not getting the windows GUI through the script. I am able to attach to the windows and then after wards a new command prompt in unix machine opens(a new process). Basically, the path of the script to launch the notepad runs in the older command prompt but it is suppose to run in the new command prompt where the screen is now attached. But I don't know how to solve this. – internalerror404 Jul 30 '14 at 04:13
  • Following link explains the problem but the solution is not useful, as windows has no support for pty. Any other ideas? http://fleckenzwerg2000.blogspot.com/2011/10/running-and-controlling-gnu-screen-from.html?m=1 When we try to spawn a screen process with subprocess.Popen() or similar, screen will immediately terminate. It will refuse to run without an own terminal, and subprocess.Popen() does not allocate a terminal for new processes. The obvious thing to do is to somehow allocate a new terminal, and connect the newly spawned subprocess to it. – internalerror404 Jul 30 '14 at 05:18
  • I was able to solve this by putting the screen command in bash profile file. But I am still trying to automate attaching and detaching to new screen in a ssh session for windows platform. So, its still not working. – internalerror404 Jul 31 '14 at 18:17

1 Answers1

0

I put the screen command in the bash profile script of cygwin user. This is working now.