[comp.sys.atari.st] Another redirection question

rogers@ncrcce.StPaul.NCR.COM (Bob Rogers) (12/17/89)

I've modified the MicroEMACS that came with the Mark Williams C compiler to
read standard input (e.g., you can put it at the end of the pipe and then
view/edit the stuff that came out the pipe).  Is there any way to re-connect
the console to standard input so that a program (which itself used standard
input) run from within the editor via system() will operate correctly?

In UNIX this is done by:
	tty = open("/dev/tty", 0);
	close(0);
	dup(tty);
	system("whatever");	/* "whatever" now has access to proper stdin */

I've tried a similar technique using the ST's "con:" device in place of
/dev/tty but to no avail.  Can anyone offer a solution?
-- 
----
Bob Rogers                    rogers@stpaul.ncr.com  or  rogers@pnet51.cts.com
NCR Comten, St. Paul, MN      GEnie: R.C.ROGERS

piet@cs.ruu.nl (Piet van Oostrum) (12/18/89)

In article <1787@ncrcce.StPaul.NCR.COM>, rogers@ncrcce (Bob Rogers) writes:
 `I've modified the MicroEMACS that came with the Mark Williams C compiler to
 `read standard input (e.g., you can put it at the end of the pipe and then
 `view/edit the stuff that came out the pipe).  Is there any way to re-connect
 `the console to standard input so that a program (which itself used standard
 `input) run from within the editor via system() will operate correctly?
 `
 `In UNIX this is done by:
 `	tty = open("/dev/tty", 0);
 `	close(0);
 `	dup(tty);
 `	system("whatever");	/* "whatever" now has access to proper stdin */
 `
 `I've tried a similar technique using the ST's "con:" device in place of
 `/dev/tty but to no avail.  Can anyone offer a solution?

Fforce (0, -1) or Fforce (0, Fopen ("con:", 0));
-- 
Piet* van Oostrum, Dept of Computer Science, Utrecht University,
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
Telephone: +31-30-531806   Uucp:   uunet!mcsun!hp4nl!ruuinf!piet
Telefax:   +31-30-513791   Internet:  piet@cs.ruu.nl   (*`Pete')

john@dynasoft.UUCP (John Stanley) (12/21/89)

[piet@cs.ruu.nl (Piet van Oostrum) writes...]
> In article <1787@ncrcce.StPaul.NCR.COM>, rogers@ncrcce (Bob Rogers) writes:

>  `I've tried a similar technique using the ST's "con:" device in place of
>  `/dev/tty but to no avail.  Can anyone offer a solution?
> 
> Fforce (0, -1) or Fforce (0, Fopen ("con:", 0));

  The first one should work, but the 2nd one has a few problems.  Better to
use Fforce(0, (int)Fopen("con:", 0)); if you have to use this method. The
example Piet gave will (on many compilers) push a long onto the stack where
Fforce expects an int...  Fopen "really" returns a long for some librarys..

  In actual practice, I'd avoid using the 2nd form altogether since it
uses up a file handle that isn't going to be freeded until the program
exits.  Do a bunch of these calls and you'd suddenly discover your
program couldn't open any more files...

---
  John Stanley <john@dynasoft.UUCP>
Software Consultant / Dynasoft Systems