0

I wish to automate the below task

  1. Launch KiTTY
  2. Enter username and password
  3. Login successfully
  4. Enter this below command to see the logs
tail -2000f /apps/test/good.log

I am able to achieve up to point 3 using below code

from subprocess import Popen
Popen("powershell kitty-0.73.1.1.exe sakthi@x.y.w.z -pw YYYY")

(new KiTTY windows is opened and user is logged in successfully)

But I don't know how to pass the below command

tail -2000f /apps/test/good.log

Note: I am using Python3

I WANT THIS AUTOMATION AT UI LEVEL. I have around 5 to 6 log files to go through while testing. I don't want to open all the logs manually. So I am looking for a way to automate it.

I am using KiTTY, because it can re-connect automatically when there is any network problem.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Kandan Siva
  • 471
  • 2
  • 9
  • 20
  • You're asking a slightly different question, but the answer is the same https://stackoverflow.com/questions/163542/python-how-do-i-pass-a-string-into-subprocess-popen-using-the-stdin-argument – Grismar Jan 06 '20 at 07:52
  • Does this answer your question? [Python - How do I pass a string into subprocess.Popen (using the stdin argument)?](https://stackoverflow.com/questions/163542/python-how-do-i-pass-a-string-into-subprocess-popen-using-the-stdin-argument) – Grismar Jan 06 '20 at 07:52
  • 1
    Why do you run PowerShell from Python to run yet another application? + Why do you even run an application to execute a command on an SSH server? Use a native Python SSH module, like Paramiko. And you won't have this kind of problems. – Martin Prikryl Jan 06 '20 at 08:21
  • @Grismar I want this automation at UI level. – Kandan Siva Jan 06 '20 at 08:43
  • @KandanSiva please look into the provided link - streaming in character data on stdin equates to a user typing the data on that stream. Unless you think there is a timing issue (where the application reads the stream before it should), this should be the solution you're after. – Grismar Jan 07 '20 at 04:04

1 Answers1

2

KiTTY, as well as PuTTY, has -m command-line switch to provide a command for SSH "exec" channel.
This is discussed in: Automating command/script execution using PuTTY

KiTTY additionally has -cmd command-line switch, which (contrary to -m) simulates key strokes on SSH "shell" channel. It is an equivalent of KiTTY "Automatic Command" feature.
See also Open command line in C# and send commands PuTTY or KiTTY


Though if you want to automate testing, you better use a native Python SSH module, like Paramiko.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992