From: Alf P. Steinbach on
* Phil Hibbs:
> Alf P. Steinbach wrote:
>> What's wrong with piping?
>
> That only works with simple programs that just use STDOUT, anything
> that draws on the screen would not work. Also I want to leave the
> Command Prompt running at the end so that the user can interact with
> it. What I'm actually doing is running a Telnet session, logging it
> in, running a couple of commands, then leaving it running.

Have you considered asking the Telnet client to log?

<example>
telnet [-a][-e escape char][-f log file][-l user][-t term][host [port]]
-a Attempt automatic logon. Same as -l option except uses
the currently logged on user's name.
-e Escape character to enter telnet client prompt.
-f File name for client side logging
-l Specifies the user name to log in with on the remote system.
Requires that the remote system support the TELNET ENVIRON option.
-t Specifies terminal type.
Supported term types are vt100, vt52, ansi and vtnt only.
host Specifies the hostname or IP address of the remote computer
to connect to.
port Specifies a port number or service name.
</example>

Just use option /k (short for "keep") for the command prompt.


Cheers & hth.,


- Alf
From: Phil Hibbs on
Alf P. Steinbach wrote:
> Have you considered asking the Telnet client to log?

The log output is buffered, and can't be read until the Telnet session
exits.

Phil Hibbs.
From: Phil Hibbs on
OK, time to re-open this old wound. I think I'm close to getting
something working.

I have one working script written using a tool called AutoHotKey, and
one non-working script written in AutoIt. I don't know AutoHotKey at
all, the scripting language is alien and strange to me so I'm having a
hard time converting it to a working AutoIt script, especially as I'm
not very familiar with the Windows API concepts that it is using.

Here is the working AutoHotKey script (search for n-l-i-d, the script
in his post works fine for me)
http://www.autohotkey.com/forum/topic36465.html

The interesting bits look like this:

if !DllCall("AttachConsole","uint",pid) { ExitApp }
; If it succeeded, console functions now operate on the target
console window.
; Use CreateFile to retrieve a handle to the active console screen
buffer.
hConOut:=DllCall("CreateFile","str","CONOUT$","uint",0xC0000000
,"uint",7,"uint",0,"uint",3,"uint",0,"uint",0)
if hConOut = -1 ; INVALID_HANDLE_VALUE
...

I tried to convert the AttachConsole and CreateFile calls to AutoIt
syntax, which ended up looking like this:
http://www.autoitscript.com/forum/index.php?showtopic=113407

The equivalent bit looks like this:
DllCall( "Kernel32.dll", "int", "AttachConsole", "int", $pCmd )
If @error Then Return SetError(1, 0, -1)
$hConsole = DllCall( "Kernel32.dll", "hwnd",
"CreateFile","str","CONOUT$", "int", 0xC0000000 _
, "int", 7, "int", 0, "int", 3, "int", 0,
"int", 0 )
If $hConsole = -1 Then Return SetError( 2, 0, -1 )

However, the $hConsole return value from the DLL call is empty.

I know this is a long shot, and most people here will not be familiar
with AutoHotkey or AutoIt, but does any of the above ring any bells?
(And please, no "what do you REALLY want to do" replies, I've been
down that road already.)

Phil Hibbs.
From: Phil Hibbs on
I'm damn close to getting this working. Everything's fine until the
Command Prompt window scrolls, and then I get nothing.

If anyone's interested in a Command Prompt automation script, take a
look at this thread:
http://www.autoitscript.com/forum/index.php?showtopic=113588&st=0&gopid=794646&#entry794646

And if you can see why it all stops working when the window scrolls,
let me know, either here or there!

Phil Hibbs.
From: Phil Hibbs on
Me:
> I'm damn close to getting this working. Everything's fine until the
> Command Prompt window scrolls, and then I get nothing.

Fixed this now - I assumed that the rectangle offset was from the top
of the buffer, but it's from the visible window so you need a negative
Y offset to get the stuff that's off the top, not a positive Y offset
to get the stuff that's visible. Yay, I have my chocolate covered
banana at last! My thanks to everyone that discouraged and insulted
me.

Phil Hibbs.