?
Solved

keeping DOS window open

Posted on 2000-03-01
9
Medium Priority
?
375 Views
Last Modified: 2010-04-10
I want to run a .exe console application in an ms-dos prompt window and keep this window open after the program is finished so the user can look at the results.  I cannot edit the program to make it pause when it is done.  I have a CString with the command line, and parameters are generated by my Visual C++ 6 program.  If there is a way to get the output of these program to the dos window and bring it into my application that would be even better, but I doubt that is possible.

Thanks,
Gabe Smedresman
0
Comment
Question by:GabeSmed
[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
9 Comments
 
LVL 3

Expert Comment

by:ufolk123
ID: 2575360
For stopping the programming to finish without warning you can use the getch() function at end of program defined in conio.h.

There is one way to get the output of your console app .You redirect the program 's stdout handle to your application's pipe etc.Look at CreateProcess() help in StartupInfo portion.If your console is interactive you can use

FILE *_popen( const char *command, const char *mode );

Please see MS help for more details.
0
 

Author Comment

by:GabeSmed
ID: 2578292
I don't think I made myself very clear.  I have an .exe program (tc32.exe) that I downloaded.  I CANNOT edit it, I did not create it.  The program I'm working on is a Visual C++ SDI Windows Application.  I need to run tc32.exe with parameters generated by the program (in a CString) and have the program dos window stay open after the program is finished.
0
 

Expert Comment

by:lexen
ID: 2578453
Have you tried creating a shortcut to it?  Then you can uncheck the "Close on Exit" box.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:GabeSmed
ID: 2578864
Then I wouldn't be able to run the shortcut with parameters from my program.

For anyone who wants it, here is my code:

void CTadsView::OnCompile()
{
      // TODO: Add your command handler code here
      CTadsDoc *pDoc = GetDocument();
      if(!pDoc->GetPathName().IsEmpty())
      {
            CString m_strLaunchedDir,m_strFileName, commandline;
            m_strLaunchedDir = pDoc->GetLaunchedDir();
            m_strFileName = pDoc->GetPathName();
            if(pDoc->IsModified()) { MessageBox("You must save the file before compiling!","Error"); }
            else
            {
                  commandline = "\"" + m_strLaunchedDir + "Exec\\tc32.exe\" -i \"" + m_strLaunchedDir + "Libs\" -o ";
                  commandline += "\"" + m_strFileName.Left(m_strFileName.GetLength()-2) + ".gam\" -ds2 ";
                  commandline += "\"" + m_strFileName + "\"";
                  //if(WinExec(commandline,SW_SHOWNORMAL) < 33)
                  
                  
                  static STARTUPINFO           StartupInfo;
                  static LPSTARTUPINFO         lpStartupInfo = &StartupInfo;
                  static PROCESS_INFORMATION   ProcessInfo;
                  static LPPROCESS_INFORMATION lpProcessInfo = &ProcessInfo;
                  
                  lpStartupInfo->cb          = sizeof( STARTUPINFO );
                  lpStartupInfo->lpDesktop   = NULL;
                  
                  char strExecuteProg[1000];
                  strcpy( strExecuteProg, commandline );
                  lpStartupInfo->lpTitle = strExecuteProg;
                  
                  //lpStartupInfo->dwX         = 0;
                  //lpStartupInfo->dwY         = 0;
                  //lpStartupInfo->dwXSize     = 0;
                  //lpStartupInfo->dwYSize     = 0;
                  lpStartupInfo->dwFlags     = (DWORD) NULL;
                  lpStartupInfo->wShowWindow = SW_SHOW ;
                  
                  lpProcessInfo->hProcess = NULL;
                  
                  
                  if( !CreateProcess(
                        NULL,
                        strExecuteProg,
                        
                        (LPSECURITY_ATTRIBUTES) NULL,
                        
                        (LPSECURITY_ATTRIBUTES) NULL,
                        true,
                        NULL,
                        (LPVOID) NULL,
                        (LPTSTR) NULL,
                        lpStartupInfo,
                        lpProcessInfo
                        ) )
                  {
                        MessageBox("Compile Failed!","Error");
                  }
                  pDoc->compiled = true;
            }
            
      }
      else
      {
            MessageBox("You must save the file before compiling!","Error");
      }
}


I need to figure out how to keep the DOS window open when tc32 finishes (it displays results that are very important)  It is aggravating because I know people are having difficulties doing the exact opposite: getting their dos window to close automatically!
0
 

Expert Comment

by:HONG
ID: 2585302
this should help
put the following line at the beginning of your .cpp file

#include <iostream>

in your int main() body
before return 0;
put the following lines:

char Stop;
cin>>Stop;

because after all your codes are executed, the computer will ask for an input from the user, only when the user input a value for Stop variable, the program then will terminate and the DOS window will be closed, thus the user can take a look at the result as long as he does not yet input the last character.

this is an easier approach, there is the other one i know. but you know, try the easier one first.

hope it will help


0
 

Author Comment

by:GabeSmed
ID: 2589515
no... I am not editing the program in the dos window - I can't, I just downloaded.  I need to run it from my SDI application, using CreateProcess, WinExec, or something else, and keep the dos window open when it is done
0
 

Expert Comment

by:lexen
ID: 2589618
What if you write a batch file that runs the program, taking in arguments, and has a pause for the last line.

Here is the simplest form - this will output three inputs that you give it.
Example: if I type in "test one two three", then the output is "one two three" and you must hit a key to exit the batch file.

--test.bat--
echo %1 %2 %3
pause
0
 
LVL 2

Accepted Solution

by:
TallBoy earned 90 total points
ID: 2592498
Change your first commandline to

commandline = "command /k \"" + m_strLaunchedDir + "Exec\\tc32.exe\" -i \"" + m_strLaunchedDir + "Libs\" -o ";

If you want to be really slick, you can check to see what version of Windows you are running, and either run "command" or "cmd" (Windows 9x for the former, or WinNT for the latter).

// *** Define vars
DWORD dwVersion;
CSTring strShell;

// *** Get os version
dwVersion = GetVersion();
 
// *** Branch based on versions
if (dwVersion < 0x80000000)
{
      // *** Windows NT
      strShell = "cmd";
}
else
{
      // *** Windows 9x
      strShell = "command";
}

 ...

commandline = strShell + " /k \"" + m_strLaunchedDir + "Exec\\tc32.exe\" -i \"" + m_strLaunchedDir + "Libs\" -o ";

Hope this helps.
0
 

Author Comment

by:GabeSmed
ID: 2593804
Well, I ended up using my own solution... But tallboy's answer was the most detailed so I'm giving him the points anyway.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

762 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