I'm opening a telnet session with the subprocess call below. I then
wait ten seconds and attempt to terminate the telnet window I created.
Unfortuantely, the telnet window remains after the 'TerminateProcess"
call below. This software works great for opening an executable
directly (i.e. Handle = subprocess.Popen("myProgram.exe), but here I'm
using the Windows 'start' command inside, which I think has an effect.
Is there another way I can force termination of the telnet session I
create ?
# CODE STARTS HERE
TSS_Log_Path = "C:\\Log_Outputs\\TSS_Log_Test.txt"
TSS_Handle = subprocess.Popen("start telnet.exe -f " + TSS_Log_Path + "
localhost 6000",shell=True)
time.sleep(10)
ctypes.windll.kernel32.TerminateProcess(int(TSS_Ha ndle._handle), -1) #
Terminate the TSS_Log
# END CODE 6 2392
Ernesto wrote: I'm opening a telnet session with the subprocess call below. I then wait ten seconds and attempt to terminate the telnet window I created. Unfortuantely, the telnet window remains after the 'TerminateProcess" call below. This software works great for opening an executable directly (i.e. Handle = subprocess.Popen("myProgram.exe), but here I'm using the Windows 'start' command inside, which I think has an effect.
Is there another way I can force termination of the telnet session I create ?
Maybe using the module telnetlib instead?
Diez
Diez B. Roggisch wrote: Ernesto wrote:
I'm opening a telnet session with the subprocess call below. I then wait ten seconds and attempt to terminate the telnet window I created. Unfortuantely, the telnet window remains after the 'TerminateProcess" call below. This software works great for opening an executable directly (i.e. Handle = subprocess.Popen("myProgram.exe), but here I'm using the Windows 'start' command inside, which I think has an effect.
Is there another way I can force termination of the telnet session I create ?
Maybe using the module telnetlib instead?
Diez
oh ok great ! But how would I create a log file. Couldn't seem to
find that here: http://python.active-venture.com/lib...t-objects.html http://pydoc.org/1.6/telnetlib.html
Plus, everytime, I tried to use the read_all object, my program crashed
pretty hard...
tn = telnetlib.Telnet("localhost",6000)
print tn.read_all()
# CRASH
Ernesto wrote: Plus, everytime, I tried to use the read_all object, my program crashed pretty hard...
tn = telnetlib.Telnet("localhost",6000) print tn.read_all() # CRASH
that's an unusual error message. are you sure you didn't get a
traceback? if so, what did it say?
</F>
Fredrik Lundh wrote: Ernesto wrote:
Plus, everytime, I tried to use the read_all object, my program crashed pretty hard...
tn = telnetlib.Telnet("localhost",6000) print tn.read_all() # CRASH
that's an unusual error message. are you sure you didn't get a traceback? if so, what did it say?
</F>
I was running it directly in a python shell. After the tn.read_all()
call, the python shell window freezes up, and I have to do a hard
termination of the shell. There is no traceback message, just a freeze.
Ernesto wrote: tn = telnetlib.Telnet("localhost",6000) print tn.read_all() # CRASH
that's an unusual error message. are you sure you didn't get a traceback? if so, what did it say?
I was running it directly in a python shell. After the tn.read_all() call, the python shell window freezes up, and I have to do a hard termination of the shell. There is no traceback message, just a freeze.
hmm. that hardly qualifies as a "CRASH"; rather, it's pretty much
what you'd expect from a read_all call: help(tn.read_all)
Help on method read_all in module telnetlib:
read_all(self) method of telnetlib.Telnet instance
Read all data until EOF; block until connection closed.
(note the "block until connection closed" part)
what happens if you use a non-blocking method instead ? e.g.
help(tn.read_very_eager)
Help on method read_very_eager in module telnetlib:
read_very_eager(self) method of telnetlib.Telnet instance
Read everything that's possible without blocking in I/O (eager).
Raise EOFError if connection closed and no cooked data
available. Return '' if no cooked data available otherwise.
Don't block unless in the midst of an IAC sequence.
</F>
Ernesto wrote: I'm opening a telnet session with the subprocess call below. I then wait ten seconds and attempt to terminate the telnet window I created. Unfortuantely, the telnet window remains after the 'TerminateProcess" call below. This software works great for opening an executable directly (i.e. Handle = subprocess.Popen("myProgram.exe), but here I'm using the Windows 'start' command inside, which I think has an effect.
Is there another way I can force termination of the telnet session I create ?
# CODE STARTS HERE
TSS_Log_Path = "C:\\Log_Outputs\\TSS_Log_Test.txt" TSS_Handle = subprocess.Popen("start telnet.exe -f " + TSS_Log_Path + " localhost 6000",shell=True) time.sleep(10) ctypes.windll.kernel32.TerminateProcess(int(TSS_Ha ndle._handle), -1) # Terminate the TSS_Log
# END CODE
Actually, the original answer I was looking for to for a "hard close"
of telnet in Windows is:
TSS_Handle = subprocess.Popen("TASKKILL /F /IM telnet.exe", shell=True)
It is almost definitely true though that it is safer to use telnetlib.
I just don't have the time to adjust my entire huge application at the
moment. Thanks all. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Earl Eiland |
last post by:
I'm running a PyWin program that executes another program using
subprocess.Popen(). Unfortunately, this other program isn't well
behaved, and frequently terminates without terminating its process....
|
by: Uri Nix |
last post by:
Hi all,
I've been trying to use (Python 2.4 on WinXP) the subprocess module to
execute a shell command (nmake in this case), and pass its output to a
higher level.
Using the following...
|
by: Ernesto |
last post by:
I launch a Windows executable and wish to close it from Python. The
code is below. Normally, my program waits for rib.exe to finish, but
I'd like to be able to close it from python if possible. ...
|
by: Cameron Laird |
last post by:
Question:
import subprocess, StringIO
input = StringIO.StringIO("abcdefgh\nabc\n")
# I don't know of a compact, evocative, and
# cross-platform way to exhibit this behavior.
# For now, depend...
|
by: Jim |
last post by:
Hello,
I need a program that will traverse a directory tree to ensure that
there
are unix-style line endings on every file in that tree that is a text
file.
To tell text files from others I...
|
by: Eric_Dexter |
last post by:
I am trying to modify a programming example and I am coming up with
two problems... first is that I can't seem to pass along the
arguments to the external command (I have been able to do that with...
|
by: Phoe6 |
last post by:
Hi all,
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping 127.0.0.1' which will have a continuous non-
terminating output in Linux.
# code
# This...
|
by: JD |
last post by:
Hi,
I want send my jobs over a whole bunch of machines (using ssh). The
jobs will need to be run in the following pattern:
(Machine A) (Machine B) (Machine C)
Job A1 Job B1 ...
|
by: geoffbache |
last post by:
Hi all,
I've always wondered why os.kill isn't supported on Windows. I found a
discussion somewhere from 2006 about this so it seems others have
wanted it, but still nothing. So I have a...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |