Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Redirect Console Output To A Text Box


I have a VB 6 applet that launches a BAT file using the shell() command, that, in turn, runs various processes. I would like to have this bat file run in the background and display the console window's output in a text box on my VB form. I've searched for solutions to this problem, but I've found none that do exactly what I'm looking for. One note, the bat file looks at Envioronment Variables on the client's system and uses those to execute various processes. It is important that any procedure I use preserve the bat file's ability to look at the system's environment variables. An example of a procedure that puts the output in a text window but somehow hijacks the bat file's ability to read Environment Variables can be found here. Can anyone point me in the right direction to learn how to accomplish this seemingly simple task (getting a bat file's console window output to display in a VB text box)? Thanks,Steve




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Redirect Console Output
I came across the following code while browsing through the API Guide.


Code:
'Redirects output from console program to textbox.
'Requires two textboxes and one command button.
'Set MultiLine property of Text2 to true.
'
'Original bcx version of this program was made by
' dl <dl@tks.cjb.net>
'VB port was made by Jernej Simoncic <jernej@isg.si>
'Visit Jernejs site at [url]http://www2.arnes.si/~sopjsimo/[/url]
'
'Note: don't run plain DOS programs with this example
'under Windows 95,98 and ME, as the program freezes when
'execution of program is finnished.

Option Explicit
Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long
Private Declare Sub GetStartupInfo Lib "kernel32" Alias "GetStartupInfoA" (lpStartupInfo As STARTUPINFO)
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type OVERLAPPED
ternal As Long
ternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type

Private Const STARTF_USESHOWWINDOW = &H1
Private Const STARTF_USESTDHANDLES = &H100
Private Const SW_HIDE = 0
Private Const EM_SETSEL = &HB1
Private Const EM_REPLACESEL = &HC2

Private Sub Command1_Click()
Command1.Enabled = False
Redirect Text1.Text, Text2
Command1.Enabled = True
End Sub
Private Sub Form_Load()
Text1.Text = "ping"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If Command1.Enabled = False Then Cancel = True
End Sub

Sub Redirect(cmdLine As String, objTarget As Object)
Dim i%, t$
Dim pa As SECURITY_ATTRIBUTES
Dim pra As SECURITY_ATTRIBUTES
Dim tra As SECURITY_ATTRIBUTES
Dim pi As PROCESS_INFORMATION
Dim sui As STARTUPINFO
Dim hRead As Long
Dim hWrite As Long
Dim bRead As Long
Dim lpBuffer(1024) As Byte
pa.nLength = Len(pa)
pa.lpSecurityDescriptor = 0
pa.bInheritHandle = True

pra.nLength = Len(pra)
tra.nLength = Len(tra)

If CreatePipe(hRead, hWrite, pa, 0) <> 0 Then
sui.cb = Len(sui)
GetStartupInfo sui
sui.hStdOutput = hWrite
sui.hStdError = hWrite
sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
sui.wShowWindow = SW_HIDE
If CreateProcess(vbNullString, cmdLine, pra, tra, True, 0, Null, vbNullString, sui, pi) <> 0 Then
SetWindowText objTarget.hwnd, ""
Do
Erase lpBuffer()
If ReadFile(hRead, lpBuffer(0), 1023, bRead, ByVal 0&) Then
SendMessage objTarget.hwnd, EM_SETSEL, -1, 0
SendMessage objTarget.hwnd, EM_REPLACESEL, False, lpBuffer(0)
DoEvents
Else
CloseHandle pi.hThread
CloseHandle pi.hProcess
Exit Do
End If
CloseHandle hWrite
Loop
CloseHandle hRead
End If
End If
End Sub

It works great with programs such as "ping" and what not. However, it closes after running the program so it doesn't allow interaction. My question is, how would I maintain the pipe to allow interaction between the user and the console. I tried WriteFile in a similiar way ReadFile was used, but it came back 0. Any help will be appreciated.

Redirect Console Output - Vb6
hi
i want to invoke a fortran console application from vb and redirect its output to a textbox at real time.

i tried the following code:

Option Explicit
Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long
Private Declare Sub GetStartupInfo Lib "kernel32" Alias "GetStartupInfoA" (lpStartupInfo As STARTUPINFO)
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type OVERLAPPED
ternal As Long
ternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type

Private Const STARTF_USESHOWWINDOW = &H1
Private Const STARTF_USESTDHANDLES = &H100
Private Const SW_HIDE = 0
Private Const EM_SETSEL = &HB1
Private Const EM_REPLACESEL = &HC2

Private Sub Command1_Click()
Command1.Enabled = False
Redirect Text1.Text, Text2

Command1.Enabled = True
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If Command1.Enabled = False Then Cancel = True
End Sub

Sub Redirect(CmdLine As String, objTarget As Object)
Dim i%, t$
Dim pa As SECURITY_ATTRIBUTES
Dim pra As SECURITY_ATTRIBUTES
Dim tra As SECURITY_ATTRIBUTES
Dim pi As PROCESS_INFORMATION
Dim sui As STARTUPINFO
Dim hRead As Long
Dim hWrite As Long

Dim bRead As Long
Dim lpBuffer(1024) As Byte
pa.nLength = Len(pa)
pa.lpSecurityDescriptor = 0
pa.bInheritHandle = True

pra.nLength = Len(pra)
tra.nLength = Len(tra)

If CreatePipe(hRead, hWrite, pa, 0) <> 0 Then
sui.cb = Len(sui)
GetStartupInfo sui

sui.hStdOutput = hWrite
sui.hStdError = hWrite
sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
sui.wShowWindow = SW_HIDE
If CreateProcess(vbNullString, CmdLine, pra, tra, True, 0, 0, vbNullString, sui, pi) <> 0 Then

SetWindowText objTarget.hwnd, ""


Do
Erase lpBuffer()

If ReadFile(hRead, lpBuffer(0), 1023, bRead, ByVal 0&) Then
SendMessage objTarget.hwnd, EM_SETSEL, -1, 0
SendMessage objTarget.hwnd, EM_REPLACESEL, False, lpBuffer(0)
DoEvents
Else
CloseHandle pi.hThread
CloseHandle pi.hProcess
Exit Do
End If
CloseHandle hWrite
Loop
CloseHandle hRead
End If
End If

End Sub

it works fine with ping command...but gives the following error with the fortran application:

forrtl: The handle is invalid.forrtl: severe (39): error during read, unit 5, file CONIN$

i tried it with batch files by redirecting output to a file..this works...but iam able to display d output in d textbox only after the fortran application completes as i am unable to access the output file while it is being written...

can sum1 plz offer a solution by either of d ways???its urgent n me all bugged up trying this ...thanx a lot....

How To Output Text To Console In Vb6?
If I invoke a vb6 windows app from the command line, how can I get the vb6 app to write text output at the command line?

Console Program I/O Redirect
Hello

I want to send some data to console program and retrieve data it sends to me. Here's code:


Code:
Public Sub RunConsole(cmdLine As String)
Dim PID As Long
Dim pa As SECURITY_ATTRIBUTES
Dim pra As SECURITY_ATTRIBUTES
Dim tra As SECURITY_ATTRIBUTES
Dim pi As PROCESS_INFORMATION
Dim sui As STARTUPINFO

Dim hStdoutRead As Long ' stdout + stderr
Dim hStdoutWrite As Long

Dim i As Integer

Dim hStdinRead As Long
Dim hStdinWrite As Long

Dim bAvail As Long ' pipe bytes available (PeekNamedPipe)
Dim bRead As Long ' pipe bytes fetched (ReadFile)
Dim bWrite As Long
Dim bString As String ' our buffer
Dim lBufLen As Long
Dim nRetries As Integer

pa.nLength = Len(pa)
pa.bInheritHandle = 1

pra.nLength = Len(pra)
tra.nLength = Len(tra)

CreatePipe hStdoutRead, hStdoutWrite, pa, 0
If hStdoutRead = 0 Then Exit Sub

CreatePipe hStdinRead, hStdinWrite, pa, 0
If hStdinRead = 0 Then Exit Sub

sui.cb = Len(sui)
GetStartupInfoA sui
sui.hStdOutput = hStdoutWrite
sui.hStdError = hStdoutWrite
sui.hStdInput = hStdinRead
sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
sui.wShowWindow = SW_HIDE

PID = CreateProcessA(vbNullString, cmdLine, pra, tra, 1, 0, Null, vbNullString, sui, pi)
If PID = 0 Then Exit Sub

lBufLen = 4096
Do Until EOF(2)
DoEvents

If Seek(2) >= LOF(2) Then Exit Do
If (LOF(2) - Seek(2)) < lBufLen Then lBufLen = LOF(2) - Seek(2)

bString = String(lBufLen + 1, 0)
Get #2, , bString

WriteFile hStdinWrite, bString, Len(bString), bWrite, ByVal 0
Loop

Do While PeekNamedPipe(hStdoutRead, ByVal 0, 0, ByVal 0, bAvail, ByVal 0)
DoEvents
If bAvail Then
bString = String(bAvail, 0)
ReadFile hStdoutRead, bString, bAvail, bRead, ByVal 0

Put #1, , bString
CloseHandle hStdoutWrite ' this turns the pipe around
End If
Loop

CloseHandle hStdoutRead
CloseHandle hStdinRead
CloseHandle hStdinWrite
CloseHandle pi.hThread
CloseHandle pi.hProcess
End Sub
The problem is that the console program won't get data I want to send to it. Please can anybody help me?

Reading Text Output Of A DOS Console (Ms-Dos ProgramRun Prev In Windows Environement)
Reading text output of a DOS console (Ms-Dos Program Run Prev in Windows Environement):

Well, here we are examining whether it is possible to obtain the console handle of a ms-dos previously run:

http://www.xtremevbtalk.com/showthre...=292302&page=1

http://www.xtremevbtalk.com/showthre...=292302&page=2

If any know if is possible obtain a Console Handle and Capture the Screen Buffer of a Ms-Dos program already run, with this code, for example???:

fsuccess = GetConsoleScreenBufferInfo(hConsoleOut, csScreenBuffer)' (This is the Important Code, appear to be that with hConsoleOut is Possible retrieve the Buffer)
'non-zero result is a success
ConsoleBoundary = csScreenBuffer.srWindow
Dim lineMessage As String * 80
readLength = 80
XPos = 0
YPos = 0
Text1.Text = ""
For YPos = 0 To ConsoleBoundary.Bottom
def = ReadConsoleOutputCharacter(hConsoleOut, lineMessage, readLength, YPos * 65536, vbNull)
If Trim(lineMessage) <> "" Then
Text1.Text = Text1.Text & Trim(lineMessage) & vbCrLf
End If
Next YPos

Appear to be the problem is retrieve the Console Handle of a Ms-Dos program that exist previously...

Is possible your contribution to this interesting problem???

Sorry for nuisances and thanks in advance!!!

Good day...

Redirect Output
Hi,

I need to redirect output from my dos box console to a form. My application calls PING.EXE to ping a certrain IP address, but I don't want it to show in a dos box. Is that possible??

And another thing, can you use an API call to register dll's instead of calling REGSVR32.EXE?? My appliation also has the capability of registering OCX and DLL files.

Thanks,
Jakkels

Use &&gt To Redirect DOS Output???
I found some posts here. They used &gt to redirect DOS output.
like this:
dir *.exe &gt; tmp.txt
When I use this &gt;, the tmp.txt is empty. The DOS returns error message " Too many parameters -tmp.txt ".

Why ?????
Anyone know????? Different DOS version????

Redirect Standard Output
Here is a demonstration project I put together a couple of years ago on this. See the source code in the project for documentation.

It uses PeekNamedPipe and ReadFile, and I haven't had any trouble with it on 95, 98, NT4 or 2000.

Administrators: Can this be placed into the code library?

Hope this helps

Redirect DOS-Shell Output
I recently came across the following code the redirects output from a dos-prompt to a textbox. My question is how would I go about maintaining and using the pipes? Would I need the WriteFile function to do this? If anyone could help me out or point me to a good website about this then I would really appreciate it. I am a complete newbie to API.

Redirect Output From DOS-Shell
I recently came across the following code the redirects output from a dos-prompt to a textbox. My question is how would I go about maintaining and using the pipes? Would I need the WriteFile function to do this? If anyone could help me out or point me to a good website about this then I would really appreciate it. I am a complete newbie to API.

Redirect Standard Output
Hi! I'm new to VB.

I'm trying to execute a shell command through VB and making it to write the output into a file.

From command line, if you type "command > file" the output is written into a file called "file", but if you do this with the Shell(path,window) function it doesn't work.

Any idea?

Redirect The Sound Output
hello
how can i redirect the sound output and input
for example the modem mic will be the sound input and the modem speaker is the output !!!?????

Redirect DOS-Shell Output
The attached project uses pipes to redirect output from a console, but it only shells the application. My question is how would I maintain and use the console? I think the WriteFile function is necessary but I don't know how to use it. Anyway, if anyone has any websites or anything that could be of any use please reply on this thread.

Redirect Dos Output (EXPERTS NEEDED)
I want to redirect the output from a dos command to my app, i tried using ">" with the dos command to redirect the output to a temp file then get the file by my app, but it is not good idea becaus some dos commands need some time to finish

I tried the "shellwait" method to make my app wait for the dos command to finish but it is making many problems to me

At last i tried to make PIPES to redirect the output of any console prog to my app, i made this using an API function called READFILE which can read the output from the pipe BUT THERE IS A SERIOS PROBLEM this method is successful if the console command is finished after excuting but if the console command waits for any input from me it makes my app Hangs

for example if i run the command "PING 127.0.0.1" , my app do it perfectly, but if i run "command.com" it gives me the following

microsoft windows ****
copyright microsoft.....

c:

then my app hangs

I think this is because when the console application is in standby mode and waiting for input from me the readfile function is getting the output from the pipe (even that the output is nothing) so it hangs my app


can anyone solve this pipe prob to me

Redirect SHELL Output Help Needed
I need to invoke a DOS FTP Shell Command and redirect that output to a text file.

I have a set of FTP instructions in a text file (in.txt). As of now I am using


VB Code:
Shell "ftp -s:C:WINDOWS empin.txt", vbHide


This will trigger the DOS FTP Prompt and pass the values defined in the text file to the DOS Window for the FTP Session.

How do I make changes to this piece of code so that I can redirect the DOS output to another textfile, Say c: rial.txt

Microsoft Speech SDK 5.1 -redirect Output
I am attempting to use Microsoft Speech SDK to enable text to speech within an IVR application. The development tool is VBVoice and I would like to avoid using Speechify. Currently, the voice output goes to the speakers on my computer. Does anyone know how to redirect this output to my Dialogic card?

Capturing And Redirect Printer Output
HI,

I am developing an App. In that I need to capture/redirect remote host's printer
output to file/.... and I need to print that captured output at local printer through
vb code.

We are not supposed to use networked printers like IP based printers.

thanx help me

Redirect Output Doesn't Work With Shell
Hi all, I've started this thread to discuss a problem I've noticed with using Shell in VB6.

If you were to go to a command prompt and type:

ping 192.168.1.1 >test.txt

it would successfully redirect the screen output of the ping command to a text file called test.txt.

However, this doesn't seem to work correctly when using the shell command within VB. For instance, the following wouldn't work:


Code:
Shell("ping 192.168.1.1 >test.txt")
It appears to work, but the test.txt file never gets created. I thought perhaps that I was doing something wrong and that Shell wasn't executing the command correctly so I tried the following to verify that shell was indeed executing the command:


Code:
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal shelledID As Long) As Long
Public Const PROCESS_QUERY_INFORMATION = (&H400)
Dim lngTaskID As Long
Dim lngPID As Long
lngTaskID = Shell("ping 192.168.1.1 >test.txt")
MsgBox("command started as Task ID number " & lngTaskID)
Do
lngPID = OpenProcess(PROCESS_QUERY_INFORMATION, False, lngTaskID)
DoEvents
CloseHandle lngPID
Loop Until lngPID = 0
MsgBox("Command successfully completed")
It is in fact running the command but not redirecting output to a text file. Ive also tried this with a different executable (Uptime.exe) that comes with the Windows NT Resource Kit and it won't redirect to text either.

Anybody run into this issue before, and if so do you know of a good way to make this work? When I say a good way, I'm not talking about an alternate way involving 200 lines of code or requiring 10 seperate API calls. In theory, this should be working but for some reason, it doesnt.

How To Redirect Output From Dos Program To Textbox In Vb2005
example

processA as Process
processA = Process.start("dosprogram.exe, ...mininmize)

output for dosprogram.exe is something like

initializing
running
percent done 1%
percent done 2%
....
percent done 100%
stopping
exit


i need some way of being able to redirect that output to a textbox or something like that is there any way to do that in vb2005?

thanks

Getting Output Of Console App.
Hi,
Suppose I have the title of a console app running in a window, how do I get the contents (text) of that window?
I don't really need stuff like "shell xx &gt; out.txt" but some means to get the output in REAL TIME as it comes out, is it possible?

Getting Console Output
Hi Buddies,
I wrote the following code to get console data but api is not working.Neither it is giving error.returning 1 and outbuffer is blank
Although WriteConsole() is working.
Pls. Help
Thanx and Regards
Yujvendra

Private Sub Form_Load()
If AllocConsole() Then
hConsole = GetStdHandle(-11&)
If hConsole = 0 Then MsgBox "Couldn't allocate STDOUT"
Else
MsgBox "Couldn't allocate console"
End If
End Sub

Private Sub Command1_Click()
Dim b, c As Long
Dim s As COORD
Dim k As Long
Dim cons As CONSOLE_SCREEN_BUFFER_INFO
Dim Result, cWritten As Long
Dim sOut As String
Dim x As String
Dim y As Long
x = String(50, " ")
sOut = String(10, " ")
sOut = "Hi There" & vbCrLf
s.x = 0
s.y = 0
r.Bottom = 500
r.Left = 500
r.Right = 1000
r.Top = 0
buf.x = 10
buf.y = 5
Result = WriteConsole(hConsole, ByVal sOut, 10, cWritten, ByVal 0&)
MsgBox Result
Shell "C:TEST.BAT"
k = ReadConsoleOutputCharacter(hConsole, x, 50, s, y)
End Sub

Capture Console Output
I tried to capture console output from my application. If there is any console output when I run the macro, it runs well... but if there is no output, the application freezes on
ReadMessage API.
Could somebody help it out...The application is just like edit plus
VJ

Capturing Console Output
How can I make my VB program run a DOS command (or a console application) and capture the output text to a label or textbox ?

How To Catch The Console Output
I'd like to run a console application so that it will print out the stuff in the program window (Text area).
How?

Output Console To RichTextbox
How do I go about exporting the text results of a DOS app and importing it into a RichTextBox in real time? Another question is if not, I can send to a text file and import from there but I having problem waiting for the app to end.



Edited by - cool1 on 1/27/2005 5:37:24 PM

Redirecting Console Output
How do I redirect a console's output to a text box etc.? I dont want the console to popup, but simply output to my text box.

For ex: The Java IDE programs direct compilers output etc(which are consoles) to a control.

Please help
Thanx

Console Output To Textbox
I want to start a DOS program (console) from my app, and instead of a console window popping up, I need the output to be displayed in a textbox in my own application.
I know it can be done, but I need to know how it can be done in VB. Thanks in advance,
Vampyre

VB And Console Output Problem
How can I output text message from VB code to the same console window (DOS box) my VB program started from ? Can you illustrate it with short sample, please

Capturing Console Output From A Game
I don't know if this is possible in all games.. but I would like to know how I can get whats like said from in game like in Soldier Of Fourtune 2 or Quake3. And put it in a textbox. Thank You

Channeling DOS Prompt Console Output
Is it possible to channel the output from a dos prompt into a textbox in a vb app? I heard something about using a pipe somewhere, but supposedly it doesn't work when you try to shell some programs with it (?) If anyone has any input it would be most appreciated.

By the way, the program that I'm trying to shell is tasklist.exe (in the system32 folder in winxp). I'm not sure if this makes a difference or not, but I just want to be sure.

Interactive Console Input And Output, This Is How It's Done
I've seen many people asking for a way to interact with console applications like ftp. I searched the entired net but couldn't find a single VB sample, so I did this little code to show how it's done. By the way, no, windows 95/98/ME doesn't allow asynchronous pipe communication.

Capture DOS Console Window Output
Hello!

I have a problem.
i have a DOS program running under windows XP. it's a dos console.
i'm looking for a way to get all the window text just by the window handle.

i was looking for a solution but all i found it an examples of inserting a commandline and get the resault.

can anyone help my?

10Q!!

Input/Output To A Console Application!
Hi,

Am looking for someway to allow a visual basic application to send and retrieve commands and results to/from a console application. I've seen JoshT's code, yet I need a version that allows me to send commands and then analyse results, then send more commands

Hope somebody can help!

Wait For Any Console Output Change
hi everybody
i need some help about vb 6.0
 i'am writing a program which uses some other exe's console output (for example for taking the output to textbox)
For using the exe's output on console i don't want to wait to exe to finish it work (exe may work for an hour).I need to see every change on console and take it to my form.
Please help me about that problem
Thanks for your interest...


 

Send Output To MSDOS Console From Program
This is my situation:

The program (will be developed in VB 6.0) contains no form and is invoked from MSDOS console. It accepts arguments and does some computations and processes then returns the result to the same MSDOS screen. such as:

Quote:





C:>TEST Argu1
Program completed successfully with return code=1010
C:>






I am stuck on sending text back to the same screen. Please tell me how to do that. Thanks ahead.

Capturing DOS Output From Console While Program Is Running
Okay, I've been searching around for ages, but can't find an answer.

I want to be able to capture DOS output from a console program, whilst it is running. All the examples I've seen have been capturing the output AFTER the program has finished executing. Does anyone know how to capture the console output whilst the console program is still executing?

Also, if possible, I want to have my own console window which can display the output of the console program. I know that if I can capture the output, I can easily send it back, however, I think this will cause all the cursor positions to be lost (eg the console program will be outputing a progress indicator).

Anyways, thanks in advance for any ideas!

Redirecting Output (STDOUT) To Both, A Console, And A File
Running Oracle sql scripts. Would like to dump contents of STDOUT to a console and to a text file. I've done the console portion of it. Need help with the text file portion. Thanks.

Doevents And Piping/redirecting Win32 Console Output
I am trying to write a front end for a console app (the app is besweet, used to decode DVD audio). In order to provide the status of the decoding I pipe the output of the program in to a textbox

Part of the code that I use to do this is below, my problem is with DoEvents. The console program initially seems to do nothing and no output is displayed but then if I move the mouse or click something or break to the IDE and resume it starts to work as intended. Removing the Doevents fixes this but then obviously the program becomes locked while the decoding takes place. Does anyone have any ideas about why this might be or how to fix this.


VB Code:
'strresult holds output'trimlines processes the output to make it suitable for the textbox,         Do While ReadFile(hRead, lpBuffer(0), 256, bRead, ByVal 0&)            strresult = strresult & StrConv(lpBuffer(), vbUnicode)            txt = trimlines(strresult)            DoEvents            Erase lpBuffer()            If bRead <> 256 Then Exit Do        Loop

I Can AppActivate("Halo Console (1)") And SendKeys "to It" , But How Do I Redirect Stdout?
Hi! I'm new!

I can AppActivate("Halo Console (1)") and SendKeys "to it" , but how do I redirect output to txtGrab.txt ?
API Spy shows it as a ConsoleWindowClass, so its basically like a DOS Window.
I've looked on here and spent houuuuuurs trying to find out how to redirect it to a field called txtGrab.txt?
Seems like I will want to redirect STDOUT to my app, but I'm not sure now.


Every thing I've listed is about as much as I have to go on. The app is a Halo Dedicated server exe, and I'm trying to send text to the app to admin remotely.

Thanks guys!


Funky



Edited by - funkytaco on 12/23/2003 5:34:22 PM

CreateProcess And Redirect StdOut To A Text File
I am using CreateProcess to execute a command line call
I want to redirect the StdOut and StdErr to a text file
All the examples I can find show how to send StdOut to a pipe, by using CreatePipe and assigning the handle to STARTUPINFO.hStdOut

I dont want to do this as the output is huge and can exceed max buffer size...

I tried to use CreateFile to give me a handle to a new file, and gave this to both hStdOut and hStdErr of my STARTUPINFO, but the file always comes up empty!

Any ideas how to redirect CreateProcess StdOut and StdErr to a new text file!

How Can Get Text From Console?
How can I get console text from another console program?

thanks

Getting Text Out Of The Console.
Is there a way to get text out of a windows?

I am running a console program on my PC. The windows looking like this



is there i way to import the text from the console to a textbox in my VB project?

Run Console Based App, And Get The Text
ok! So, basically i am running an app, using Shell(), that opens up a console window, and prints all of it's output to there. What i would like to do, is have it so that instead of a console window opening up for it's output, it's output goes into my textbox.

is this possible (i could swear i've seen it done before, but i can't seem to find anything again)? And if it is, does anyone happen to know how?

Thanks a bunch!

Reading Text From Console ???
How do I get a vb program to read the text in a console / cmd window that is running a batch file ??
I tried doing this using pipes to the stdout and it ended up a big mess.. any other ideas ?

-==- Help: VB6: Sending Text To A Console Window?
Hi,

I am trying to send text to a console window, but it has some errors, like when you send the same character 2 times in a row it only does one. Here is my code:


Code:
Option Explicit

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Private Const WM_CHAR = &H102

Private Sub cmdTest_Click()
Dim ConsolehWnd As Long
Dim i As Integer
Dim X As String

ConsolehWnd = FindWindow("ConsoleWindowClass", "jk2ded.exe")
If ConsolehWnd = 0 Then Exit Sub

For i = 1 To Len(txtTest.Text)
X = Mid(txtTest.Text, i, 1)
PostMessage ConsolehWnd, WM_CHAR, Asc(X), 0&
Next i
PostMessage ConsolehWnd, WM_CHAR, Asc(vbNewLine), 0&
End Sub


When I try sending "say Hi!!!", it only sends "say Hi!", is there a way to fix that? Maybe a different method? =

*NOTE* if it matters, this is for the game Jedi Knight 2 Jedi Outcast dedicated server executable, and I'm trying to send text to it, and its a DoS console window(like I mentioned before lol).

How Can You Grab The Text From A Console Window Or Something?
check the attachment

how can you retrieve text from something like that?

Help With Text Based RPG Script Console
I have just started a game console that is script called Lightning. I need to know if there is a way for visual basic to read "code" line by line from a Rich Text Box. I need it to read it, then performe it. For instance, if it says...

Clear
Addtext <Hello!>
Clear
End

then visual basic should read Clear, and clear the game text box.
Then it reads Addtext <Hello!> and prints "Hello!" on the screen.
Then it reads Clear, and clears the game text box again.
Then it reads End, and closes the game form, but does not exit the program.

Is this possible using only VB6 script? Respond SOON! thanks



Edited by - cheeseboneinc on 3/26/2005 5:15:42 PM

Read Text From Call Of Duty 2 Console
Is there any way I can have a VB6 app to read the text in another application, such as a Call Of Duty 2 console window?

I need to periodically read this text and then I can parse it for abusive language so that I can have the system take action instantly.

Copyright 2005-08 www.BigResource.com, All rights reserved