 |
|
 |
Hi
I think this program is underrated. It is extremely useful. One problem I had is that if you run cmd.exe in the console and try to shut it down while cmd.exe is in the middle of executing a program, the thread that reads the console will not be signaled and will crash. If it helps anyone this is the solution I have used.
1. create a global variable (DWORD m_dwKillThread;) in Application.h
2 Set the value of m_dwKillThread to 0 in CApplication::Start (Application.cpp)
3. In CApplication::Stop() add the line m_dwKillThread = -1; like so
if ( m_dwProcessId )
{
m_dwKillThread = -1;
4. In the ProcessThread(LPVOID lpApp) loop, immediately after the line
pApp->read();
add:
if (pApp->m_dwKillThread == -1) //set in Stop
{break;}
This will clean up and shut the thread down cleanly. I am sure there are better ways to do this, but this does work.
Bertram
Bertram
|
|
|
|
 |
|
 |
Hi, Franky
can you post one more project on redirecting console print job?
for example Lpt1 to Usb?
|
|
|
|
 |
|
 |
Hello
Your description is tooo short.
It does not become clear what your article is about.
It seems you wrote a DLL which must be registered as ActiveX control to be used in a Visual Basic 6 application.
The code I saw in your file "Redirect_p.c" is really ugly!
It must not be soooo complicated to redirect Console output!
If you came here because you are searching an easy way to capture the output of a Console application there is a MUCH easier way for you:
Have a look at the article CaptureConsole.dll.
The main features are:
1.) The coding is much easier for you: You don't have to implement a receiving Pipe in your main application.
2.) With two lines of code you call a console application invisibly, wait until it exits and get all its output and the Exit Code.
3.) All the funcionality is in a DLL, so it can be used in ANY project independent of the compiler: VB6, C++, .NET, Java, Delphi....
4.) You get stdout and stderr separated (optional)
5.) The DLL is thread save
6.) Timeout (optional)
7.) Codepage conversion
8.) Clean error handling
Elmü
|
|
|
|
 |
|
 |
I do not agree with you. The console redirector that you mention as being so much better (which I believe you wrote) has no realtime capacity and is therefore of little use to anyone.
You say "The code I saw in your file "Redirect_p.c" is really ugly!". Are you sure you have read it? The file is in fact called "application.cpp" and is, in my view, quite elegent. The only only addition that is needed is code to shut down any children that the console may have spawned in an orderly and safe way. There is also a potential overflow of the main buffer.
I have found it extremely useful and thank the author for his work and generosity.
Bertram
|
|
|
|
 |
|
 |
Hello Bertram
> Are you sure you have read it?
I just downloaded the ZIP file RedirectSource.zip again.
It contains a file Redirect_p.c which is 50 kB of size.
This file has more than 1500 lines of code.
This code does not have any comment and is very weird.
There is no need to write so much code for a console redirector.
I don't like things that are more complicated than necessary and additionally come without ANY documentation.
But if you like it, use it!
You are free to do what you want.
I just posted an alternative.
Elmü
|
|
|
|
 |
|
 |
Hi Elmü.
I apologise. I seem to have shot myself in the foot. doh. I have done a fair bit of work on this project, and because the two .c files are not part of the actual project, I had not looked at them myself! You are right. They are rather weird and incomprehensible. The .cpp project file is much better. Sorry for the sharpness of my remark.
I do, though, stand by my view that a console redirector needs to work in realtime.
Bertram
Bertram
|
|
|
|
 |
|
 |
Hello
> I do, though, stand by my view that a console redirector needs to work in realtime.
This depends on what you want you do!
You cannot say this in gerneral.
There are many console applications that do their work and when they have finished they return a success code or an error message. In this case there absolutely NO need to get the output in realtime. You get the result when the work is done.
The stuff with the realtime will only work when the console application flushes the buffer after each printing. Otherwise there is no RELIABLE way to get the output in realtime. See my article for more details.
Elmü
|
|
|
|
 |
|
 |
This control is fantastic!
Just what I have been looking for to incorporate an DOS program into a VB6 GUI.
I just have one issue, I want to run multiple cmd.exe 'sessions' and get the stdout from a specific session and send it a a specific VB6 control (e.g. text box). The same goes for the stdin. Is there any way to do this with the control as it is now? Or would the control need to be updated?
As you would guess I am not the world's best programmer!
tfer
|
|
|
|
 |
|
 |
This is just excellent! I've been trying to figure out the best way of parsing console output for days now. This helped me along the way. Thank you
|
|
|
|
 |
|
 |
good program!
I would like to try this dll in visual c#, but don't know how. is there any way to do that? thanks
|
|
|
|
 |
|
 |
When I try the ftp utility the prompt is never printed 'ftp>' and when you are logging in, the program holds on just typing the user
In spite of that it's a great utility ! Thanks !
Here I post before the same message
|
|
|
|
 |
|
 |
When running your sample VB application, I notice that nothing is posted to the screen until after the console process has exited. For a long running application this means that the user cannot see any messages normally printed to the console window during program execution. Is there a remedy for this?
BertV
|
|
|
|
 |
|
 |
This is probably because the application doesn't flush the stdout. When the application exits, this is done automatically, and that's why you see the screen only when the application ends.
|
|
|
|
 |
|
 |
can the control be used in vbscript or javascript
to capture output and add the output to an
edit control in an html page
|
|
|
|
 |
|
 |
This control is not safe for scripting. This means that you are not allowed to execute this code from vbscript or javascript. I'm not going to allow that, because this can be very dangerous. Someone could use this control for executing some code on your computer. What if someone used this to run a virus, delete files-program, ...
This is what microsoft says about it:
Marking your control safe for scripting tells users that there's no way a script on an HTML page can use your control to cause harm to their computers, or to obtain information they haven't supplied willingly.
Marking your control safe for initialization lets users know there's no way an HTML author can harm their computers by feeding your control invalid data when the page initializes it.
|
|
|
|
 |
|
 |
I'm not sure about the edit control in the html page, but redirect can be used in scripts. An example below (simular to the original example, but rewrote for VBScript). The trick in script is to keep the script running while waiting for the ProcessEnded event. Excellent control Franky Braem! Thanks for the work...
Set oLaunch = CreateObject("Redirect.Application","oLaunch_")
oLaunch.Name = "cmd.exe"
oLaunch.BufferSize = 8192
oLaunch.Wait = 10
oLaunch.Start
oLaunch.Write "dir" + vbCrLf
oLaunch.Write "exit" + vbCrLf
Sub oLaunch_DataReceived(sData)
WScript.Echo sData
End Sub
Sub oLaunch_ProcessEnded()
wscript.quit
End Sub
While 1
WScript.Sleep 100
Wend
|
|
|
|
 |
|
 |
Hi
Very nice compoment. I have tried to write a MFC app to test the Redirect without success.
Can you please provide a example for MFC as well ?
Thanks
/Th
|
|
|
|
 |
|
 |
I haven't used my control in an MFC program yet. I've written several controls now, but used them only in VB. When I've got the time I'll give it a try in MFC
|
|
|
|
 |
|
 |
Would it be possible for this to link up with other apps? Like the console mode programs you can do in VC++? I am an atl newbie.
Thank
|
|
|
|
 |
|
 |
You can use this control to launch a console program and to redirect the stdin/stdout to your program. You can compare it with the outputwindow of VC+
|
|
|
|
 |
|
 |
You said in your submission:
> It's even possible to redirect MS-DOS commands to your
> application.
MS-DOS is not the same as Win32 console mode. Your code
does *not* make it possible to redirect from a true MS-DOS
box under Windows (e.g MS-DOS 6.22 running under WinNT).
The NTVDM is running the DOS-box in a separate VM, and AFAIK there is no easy way to duplicate and redirect handles across VM-boundaries.
Gisle V.
|
|
|
|
 |
|
 |
Ok what I really meant was that you can redirect command.com and cmd.ex
|
|
|
|
 |
|
 |
i am trying to use the console redirect example you have given under win 98. but it does not work. the example is to run command.com and execute the dir command and the text box in VB would show what is produced in DOS shell. but it doesnt show anything. any help please?
regards
Mohith
be the change that you want to see in the world
|
|
|
|
 |
|
 |
i have working with unix redirecting server client
|
|
|
|
 |
|
 |
I just downloaded the "demo project" and "source". There are problems with both.
The "demo project" appears to be a test bed for an "EditListCtrl" and features a PictureBox called EditListCtrl1. Furthermore, it can't load because the form1.frx was not included in the zip file. Nowhere does the project refer to the Redirect object.
The "source" download features Redirect.dsp and Redirect.dsw that apparently were created with the project name of "Launch". The workspace refers to the Launch project; The Launch project refers to all of its builds as "Launch".
By loading the .ds? files as text and globally replacing "Launch" with "Redirect", I was able to at least compile the source code.
|
|
|
|
 |