[comp.sys.sgi] Beginner! How do I do text?

hart@BLACKJACK.DT.NAVY.MIL ("Michael G. Hart") (11/16/90)

Warning!: Beginner question ahead!

I want to have a program pop a window, and have all stdi/o
go to the new window.

I know I can use the cmov2s() and charstr() functions, but I'd
like to be a little more portable, and less graphic - 
my initial requirements are for non-graphic programs.

Should I fork a wsh, then kill the parent?  Since this will
only leave the child, will it's stdi/o go to the new wsh?  

Am I really missing the boat here?

Please don't tell me RTFM; there are seven of 'em spread out in 
front of me.

karron@KARRON.MED.NYU.EDU (11/18/90)

Here is a neat trick to prompt a user for input. You can test for a window
and then decide to popen or putline(), getline(). Or another neat trick is
to popen to a shell script that test for graphics, and does an echo/read
or does a launch. Hack this up to do what you want. Put in an argument for
your prompt and return value (GetInputFromUser(char *prompt,char *response);

This will get you started. Don't be shy to post what works for you.

-----------------cut here and there--------------------------------------------
/*
 * Example of how to get a string from the user nicely
 * --gavin     (gavin@sgi.com,  (415)335-1024)
 */
#include <stdio.h>
#include <string.h>

void GetInputFromUser(char *s, int len_s)
{
        char launchline[300];
        FILE *fp;

        sprintf(launchline, "launch -m 'Hello There Boys and Girls' -h echo");
        if ((fp = popen(launchline, "r")) != NULL)
        {
                fgets(s, len_s, fp);
                pclose(fp);
                /* Strip off trailing newline */
                if (s[0] != '\0' && s[strlen(s)-1] == '\n')
                {
                s[strlen(s)-1] = '\0';
                }
        }
        else s[0] = '\0';
}
#ifdef MAIN
main()
{
        char s[100];

        while(1)
        {
        GetInputFromUser(s, 100);

        if (s[0] != '\0')
                fprintf(stderr, "User entered: %s\n", s);
        else
                fprintf(stderr, "Nothing entered\n");
        }
}
#endif MAIN
------------------don't forget to cut here too---------------------------------

>From: "Michael G. Hart" <hart@blackjack.dt.navy.mil>
>Date: Fri, 16 Nov 1990 10:52:50 EST
>X-Mailer: Mail User's Shell (7.1.1 5/02/90)
>To: info-iris@BRL.MIL
>Subject: Beginner! How do I do text?
>Status: O
>
>Warning!: Beginner question ahead!
>
>I want to have a program pop a window, and have all stdi/o
>go to the new window.
>
>I know I can use the cmov2s() and charstr() functions, but I'd
>like to be a little more portable, and less graphic -
>my initial requirements are for non-graphic programs.
>
>Should I fork a wsh, then kill the parent?  Since this will
>only leave the child, will it's stdi/o go to the new wsh?
>
>Am I really missing the boat here?
>
>Please don't tell me RTFM; there are seven of 'em spread out in
>front of me.
>
>
>
+-----------------------------------------------------------------------------+
| karron@nyu.edu (mail alias that will always find me)                        |
|                                         Dan Karron                          |
| . . . . . . . . . . . . . .             New York University Medical Center  |
| 560 First Avenue           \ \    Pager <1> (212) 397 9330                  |
| New York, New York 10016    \**\        <2> 10896   <3> <your-number-here>  |
| (212) 340 5210               \**\__________________________________________ |
| Please Note : Soon to move to dan@karron.med.nyu.edu 128.122.135.3  (Nov 1 )|
+-----------------------------------------------------------------------------+