[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

urgent====> displaying in command line

Posted on 2003-12-05
16
Medium Priority
?
591 Views
Last Modified: 2010-04-17
Hi experts,
          I am currently in a project of incorporating command line interface in to  a dilaogue based program in vc++.I am able to parse the commands, But there is one problem. I can't show the output to the command line window.I used setwindowhandle, getwindowhandle almost all functions related to getting command window handle.But in vain. Please anyone suggest me a way to get the output get buffered to command line window.I heard using a pipe to route will help. Please provide me help on this (code snippet preferred), or any other way through which I can accomplish this.

GM  
0
Comment
Question by:google_man
[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
  • 6
  • 4
  • 4
16 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9880889
since it is CLI, wont a normal cout do it for you ?

If you have window of your own, that is, your process has a different controlling window and different one from which it was launched, in that case,
close stdout (1)
dup the input handle for other window
use cout...

anyway, in such case you will be doing something similar for stdin too
0
 

Author Comment

by:google_man
ID: 9880970
Hi sunnycoder,
                      I tried it with cout. but of no use. I want to display the output to same parent window thought whwich I gives the input. Can u please explain whether I can achieve through output piping.

GM
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9880975
can you give some more details about your program ...

Where do you implement the CLI, the same window from which your program is launched or do you create a new window and input/output commands from this new window ...
If latter, then how are you reading in commands ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:google_man
ID: 9881096
Hi sunny,
               I implement the CLi from the same window from which I launch the program. Then through  function parsecommandline I get the commands  that I enter as a string and then process it( char* cmdLine = AfxGetApp()->m_lpCmdLine). Earlier in the program a dialogue box was shown when we execute the command. Now I put showidilaogue fasle and called  GetWindowText(GetNextWindow(GetTopWindow(AfxGetMainWnd()->GetSafeHwnd()), GW_HWNDNEXT),, where I handle the coommand line arguments, which I get a s a string from the comand window. But can't display it in the window

GM
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9881176
> I implement the CLi from the same window from which I launch the program
All you need to do to read in commands is cin and to write out output is cout ...
All the additional things that you seem to be doing is overhead

cout should display on the window unless you explicitly did a close(1) or close (stdout)
0
 

Expert Comment

by:mem_fam
ID: 9884989
VC++ help says: "The system creates a new console when it starts a console process, a character-mode process whose entry point is the main function." I think that without main() you application cannot use cout - there is none to open it! If your application is a GUI, it most probably is written with WinMain() of its own, and by default there is no console associated with it, even if you launch it from a command line. For this reason once you start a GUI application from a command line, you immediately see a command line prompt, and can key in the next command.

Probably the simplest way to achieve what you want would be to write a small console application what would invoke CreateProcess for you GUI executable, and in StartupInfo parameter would specify STARTF_USESTDHANDLES flag and set hStdOutput, hStdInput and hStdError to the handles of the console process you created. Then your GUI process would start with console handles ready, and you will be able to write any way you want - e.g. WriteFile, and probably even cout
0
 

Expert Comment

by:mem_fam
ID: 9885045
By saying "small console application" I meant an application that has its own main() - run-time library will then assign its own entry point, and will know to associate console window with the process when it starts:

#include <stdio.h>
#include <windows.h>
main () {
   STARTUPINFO s = {.., STARTF_USESTDHANDLES, ...};
   ...
   s.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
   ...
    CreateProcess ("GUI.EXE", ...., &s, ...);
   Wait (...);
}
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9887876
>If your application is a GUI, it most probably is written with WinMain() of its own, and by default there is no console associated
>with it,
He is building a CLI !!!! Why would he ever go in for a GUI ...
google_man if you are going in for a GUI then I am surprised ... What good sense does it make to have GUI for a CLI application

Anyway, are you having console application or windows application .. If latter, then what mem_fam makes good sense
0
 

Expert Comment

by:mem_fam
ID: 9889209
The original question says:
"I am currently in a project of incorporating command line interface in to  a dilaogue based program"

My understanding was that the guy has an existing GUI program, and wants to turn it into CLI+GUI. If this is a misunderstanding, my suggestions would not help, of course.  
0
 

Expert Comment

by:mem_fam
ID: 9947611
google_man,
Any news? Have you succeeded?
0
 

Author Comment

by:google_man
ID: 10009369
Hi mem_fam,
                    Sorry for the delay. I was out of station for almost 1 month. I watched ur comments. Can u please elaborate on "console application" that I should develop. How I should call ithat console application from the GUI application.....


Thanks in advance

GM
0
 

Expert Comment

by:mem_fam
ID: 10024584
Hello google_man.

What I meant is vice versa: create console application that will call your existing GUI app and pass its own console handle to it, like in my example:

#include <stdio.h>
#include <windows.h>
main () {
   STARTUPINFO s = {.., STARTF_USESTDHANDLES, ...};
   ...
   s.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
   ...
    CreateProcess ("GUI.EXE", ...., &s, ...);
   Wait (...);
}

You will need to always start this console application first, and it will start the GUI app. The GUI app will then be able to print in the console app's window.

Happy New Year.
0
 

Author Comment

by:google_man
ID: 10027553
Hi mem_fam,
                    I have 1 doubt. My GUI application doesn't have a main(). It 's accepting command line arguments in a string through parsecommandline function. Now Iam starting GUI thjrough msdos console. So Now If I call through console. How will it work?GUI application istelf doesn't have a console interface.....


Happy New Year(Belated)


Google_man
0
 

Accepted Solution

by:
mem_fam earned 400 total points
ID: 10269360
Sorry for the delay - I apparently missed mail notification on your question.

If you create a GUI process, pass handles to it and set STARTF_USESTDHANDLES (like in my example), the GUI process will inherit console handles form console process, and will be able to write to there.



0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn different types of Android Layout and some basics of an Android App.
Six Sigma Control Plans
Introduction to Processes

650 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