TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: All
from: Tom Brown
date: 1996-02-28 18:12:04
subject: Remote control of text m

Hi :

I'm trying to remotely control a text mode app.  In this case, Telnet.
 I have some code, but it doesn't work properly.  It allows me to
receive text from it, but not write to it.  I'm probably doing
something stupid, as it looks like an easy technique.  If someone could
point me in the right direction, or even to some reference, my life
would be a better place to be.

Note that I can type into the window running this program and the
output will go to COM2.

___--begin code-----


#define     INCL_DOSQUEUES
#define     INCL_DOSNMPIPES
#define     INCL_DOSPROCESS
#define     INCL_DOSFILEMGR
#define     INCL_DOSDEVIOCTL
#include        


#include        
#include        


#include        


#include        "applicat.h"

#define     HF_STDIN    0
#define     HF_STDOUT   1
#define     HF_STDERR   2


int main (int argc, char * argv[])
{

    int                 iErrorLevel = 0;
    HFILE               hf;
    HFILE               hfStdOut = HF_STDOUT;
    HFILE               hfStdIn  = HF_STDIN;
    HFILE               hfStdErr = HF_STDERR;
    HFILE               hfOldOut = -1;
    HFILE               hfOldIn  = -1;
    HFILE               hfOldErr = -1;

    USHORT              usBPS = 300;
    ULONG               ulParmLen = 2;
    ULONG               ulAction;
    APIRET              rc;
    RESULTCODES         resc;
    CHAR                szFailName[CCHMAXPATH];


        rc = DosOpen ("COM2", &hf, &ulAction, 0, FILE_NORMAL,
FILE_OPEN,                       OPEN_ACCESS_READWRITE |
OPEN_SHARE_DENYNONE, (PEAOP2) NULL);


//      rc = DosDevIOCtl (hf,
//                        IOCTL_ASYNC,
//                        ASYNC_SETBAUDRATE,
//                        (PULONG) &usBPS,
//                        sizeof (usBPS),
//                        &ulParmLen,
//                        NULL,
//                        0,
//                        NULL);


        //  Save the old handles.

        DosDupHandle (HF_STDIN,  &hfOldIn);
        DosDupHandle (HF_STDOUT, &hfOldOut);
        DosDupHandle (HF_STDERR, &hfOldErr);


        //  Connect to the new handles.

        DosDupHandle (hf, &hfStdIn);
        DosDupHandle (hf, &hfStdOut);
        DosDupHandle (hf, &hfStdErr);


        //  Run the app.


        DosExecPgm (szFailName,
                    sizeof (szFailName),
                    EXEC_ASYNC,
                    "127.0.0.1",
                    (PSZ) NULL,
                    &resc,
                    "telnet.exe");


        //  This certainly didn't work!

//      DosExecPgm (szFailName,
//                  sizeof (szFailName),
//                  EXEC_ASYNC,
//                  (PSZ) NULL,
//                  (PSZ) NULL,
//                  &resc,
//                  "cmd.exe");




        //  Restore the old handles.

        DosDupHandle (hfStdIn,  &hfStdIn);
        DosDupHandle (hfStdOut, &hfStdOut);
        DosDupHandle (hfStdErr, &hfStdErr);


        rc = DosClose (hf);

    return (iErrorLevel);
}



___--end code-----

Thanks in advance,

Tom

 * KWQ/2 1.2g * Practice random kindness and senseless acts of beauty.

--- GEcho/2 1.20/Pro
* Origin: The Green Zone (1:140/23)
SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 140/23 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.