views:

50

answers:

1

I need to write one line at a time (user iterative process) to a command prompt that is already open.

I'd like to use VB or VBA. I know there is AppActivate, but then how do you write to it?

The command prompt is run by another program (that I can't touch).

Suggestions?

+2  A: 

You can attach to an already open console window using the Windows API function AttachConsole (sample VB code).

Private Declare Function AttachConsole Lib "kernel32" (ByVal hConsoleHandle As Long) As Long

You can then write to STDOUT using this sample.

0xA3
It seems like this is what I'm looking for, however I need to switch it to VB.NET. API's still don't make a ton of sense to me, but this is what I changed it to: Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, _ ByVal lpBuffer As String, ByVal nNumberOfBytesToWrite As Long, _ ByVal lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As LongHowever, I'm getting an error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Scott J.