The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Ghirai on August 05, 2005, 05:24:58 PM

Title: Console question
Post by: Ghirai on August 05, 2005, 05:24:58 PM
Say i have a console app, that's running, and from time to time adds some text to the console window.

What i want to do, is to hide the console, and write a windowed application, that gets the text from the console, and diaslays it in a textbox.

I was thinking in starting the console app (and removing it from the taskbar) with "consoleapp.exe >> out.txt", and constantly checking if there's new text. What do you think?

Thanks.
Title: Re: Console question
Post by: Mark Jones on August 05, 2005, 07:19:05 PM
Start your console app from within the GUI app:


    invoke ShellExecute,hWnd,0,addr MyFilePath,0,0,SW_HIDE
Title: Re: Console question
Post by: hitchhikr on August 05, 2005, 07:26:46 PM
CreatePipe -> CreateProcess -> WaitForSingleObject -> ReadFile -> etc.
Title: Re: Console question
Post by: Ghirai on August 05, 2005, 09:33:43 PM
Thanks, you're right, i forgot about that.
Title: Re: Console question
Post by: Ghirai on August 05, 2005, 11:24:02 PM
Can't figure out what's wrong here.

GetData proc hDlg:dword

.while bStop!=1

invoke PeekNamedPipe,Read1,0,0,0,addr lpNumberOfBytesRead,0
.while lpNumberOfBytesRead

invoke ReadFile,Read1,addr buffer,MAX_PATH,addr lpNumberOfBytesRead,0
.if !eax
.break
.else
invoke SendDlgItemMessage,hDlg,IDC_TXT_LOG,EM_REPLACESEL,0,addr buffer
invoke SendDlgItemMessage,hDlg,IDC_TXT_LOG,EM_SETSEL,-1,0
.endif

invoke PeekNamedPipe,Read1,0,0,0,addr lpNumberOfBytesRead,0

.endw

.endw


This thread is called after createprocess. It works, but if the console app displays some text after say 30 seconds after start, it doesn't work.
The code above only seems to get the starting text.
Title: Re: Console question
Post by: hitchhikr on August 05, 2005, 11:51:57 PM
What might be hidden inside that mysterious PeekNamedPipe ?
Title: Re: Console question
Post by: Ghirai on August 06, 2005, 12:03:19 AM
Yeah, that was it.
Works fine now.