HomeProjectsServicesContactus
» Guest
  Sign In     Register    
Projects » CvConsole
Developer : Ritey
Date : 2005-03-27 00:00

» Summary :

Class for spawning a console application and redirecting the stdin/out for the classes control.

» Catagories :


  • Development Status: Planning

» Latest Project Downloads:

Total Download Count For Project : 317
 
CvConsolecvconsole.zip
 2005-11-27Source Code3 KbNotes / ChangesMD5:e717c98be0b8307844e38120931cfbb2317 HitsDownload
 

» Project Information :

Class CVConsole

This class is used for spawning applications that use the console for input and output. The input and output is then redirected to this class. Thus no console window is show, but all output is read from a thread in the class, and console input is sent via a method in this class. It works by creating anonymous pipes and setting them as the stdin and stdout handles for the app to be spawned. When text is available to read a callback is called and the user of the class can parse the results.

Methods:

::StartConsole()
This method is used to spawn the app. And change the stdin/out handles so the class read/write to/from them. A user defined callback procedure is supplied for the caller to recieve output from the app and its exit code.

::IsRunning()
After the app has been spawned, this method will find out if the app has closed.

::TerminateConsole()
This is used to terminate the running app forcably and the cleanup.

::Write()
Write is the same as useing keyboard input to a console. What characters are in the string is what is sent to the app.

Sample Usage:
Code:
void lpread(char *buffer, DWORD len) {
    if (buffer) {
        //print the output
        printf("%s",buffer);
    } else {
        //app has exited
        printf("App Exited With Code: %d", len);
    }
}

void main( void ) {
    CVConsole mcon;

    //Spawn cmd.exe (the command prompt)
    mcon.StartConsole("cmd.exe",lpread);

    //send a command to it
    mcon.Write("dirrn");

    //send another command
    mcon.Write("exitrn");

}


This will produce an output similar to:-

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:>dir
Volume in drive C has no label.
Volume Serial Number is B12X-5F5G

Directory of C:

24/01/2005 20:37 0 AUTOEXEC.BAT
24/01/2005 21:03 22 BIOSSTR.INI
24/01/2005 20:37 0 CONFIG.SYS
8 File(s) 22,242 bytes
3 Dir(s) 14,819,876,864 bytes free

C:>exit
App Exited With Code: 0
0 member(s), 17 guest(s)
| Site Map | Statistics | Terms of Use | Privacy Policy |
Copyright (C) GoCoding.Com 2004-2007
Powered by Seditio
Contacts