Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Write to the console that started app from GUI app

Posted on 1997-05-30
12
Medium Priority
?
566 Views
Last Modified: 2013-12-03
System: P150,80MB RAM, NT4.0SP3
I have a CLI program that execs a GUI application.
Just for grins, I want to write to the console that
the GUI application started from.
I set the startupinfo structure like:
      si.hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
      si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
      si.hStdError=GetStdHandle(STD_ERROR_HANDLE);
      si.dwFlags = STARTF_USESTDHANDLES;
      
I also set bInheritHandles in both the Thread's
SECURITY_ATTRIBUTE and the Processes' SECURITY_ATTRIBUTE
to TRUE.
I call CreateProcess, and the GUI app gets the proper
handles, and when I call WriteConsole (or WriteFile),
and then call FlushFileBuffers (or fflush, or
FlushConsoleInputBuffer or no flush calls) the function
returns properly (non-zero) and the number of characters
written is returned, but I get nothing on the console.

According to the SDK docs,
(mk:@ivt:pdref/native/sdk/win32/func/src/f25_7.htm)
console output is not buffered in WinNT, so I am pretty
sure I dont need FlushFileBuffers, but it was a good try.

Is this possible?
I know that it isnt that important, but it is driving
me crazy.
Help!
0
Comment
Question by:weloytty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 4
12 Comments
 
LVL 3

Expert Comment

by:byang
ID: 1397757
First, try flush the buffers. Make the GUI program a child process of CLI program. Make sure the handles are inheritable by the GUI program.
0
 

Author Comment

by:weloytty
ID: 1397758
Edited text of question
0
 

Author Comment

by:weloytty
ID: 1397759
Thanks for the input, but alas, fflush, FlushFileInput, and FlushConsoleInputBuffer didnt work.  The SDK docs say console output is not buffered in NT.Thanks for the try, though.
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:weloytty
ID: 1397760
Edited text of question
0
 
LVL 3

Expert Comment

by:byang
ID: 1397761
One more thing to try: use DuplicateHandle() to create handles for the GUI program.


0
 
LVL 15

Accepted Solution

by:
NickRepin earned 200 total points
ID: 1397762
I am afraid, you cannot write to parent's console because 'GUI processes are not attached to any console when they are created'.
You can invoke GetConsoleTitle in GUI app, and it will return error code 6 (invalid handle).

The only way to create the console for GUI app is calling to AllocConsole().

0
 
LVL 3

Expert Comment

by:byang
ID: 1397763
No, doesn't AllocConsole() gives the GUI app a new console ? And it's not related to the CLI console.

I think DuplicateHandle() on the CLI-side, and SetStdHandle() on the GUI-side are needed.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1397764
AllocConsole gives GUI app the new console.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1397765
AllocConsole gives GUI app the new ordinary console (like any over console, eg MSDOS). And you can read/write to it without any problem.

There are terms 'attached console' in MS SDK. Do they mean that it's not enough to GUI app to have parent's console handles, but also be attached to console? I think, yes.

That's MS SDK say:
'A process can use the DuplicateHandle function to create a duplicate console handle that has different access or inheritability from the original handle. Note, however, that a process can create a duplicate console handle only for its OWN use. This DIFFERS from other handle types (such as file, pipe, or mutex objects), for which DuplicateHandle can create a duplicate that
is valid for a different process.'

By the way, what is CLI? I guess, it's console-mode application?

0
 
LVL 3

Expert Comment

by:byang
ID: 1397766
CLI stands for Command Line Interface, as opposed to GUI.

0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1397767
Thanks, that's exactly what I mean.
0
 

Author Comment

by:weloytty
ID: 1397768
I have pretty much come to the conclusion that it can't be done. I have implemented a fake--I use a memory mapped file to pass stuff back and forth, and it LOOKS like it works, so I got what I wanted, I just didnt get to do it the way that I wanted to.Thanks,
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question