Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!mcsun!unido!laura!heike!klute From: klute@heike.informatik.uni-dortmund.de (Rainer Klute) Newsgroups: comp.sys.atari.st Subject: Re: re-direction Message-ID: <2094@laura.UUCP> Date: 11 Apr 90 08:14:44 GMT References: <1602@electro.UUCP> Sender: news@laura.UUCP Reply-To: klute@heike.informatik.uni-dortmund.de (Rainer Klute) Organization: University of Dortmund, FRG Lines: 48 In article <1602@electro.UUCP>, ignac@electro.UUCP (Ignac Kolenko) writes: |> |>what is the "official" method of doing io-redirection in software. |>what i want is for program A to run. It prints to the screen using Cconws();. |>In the course of running A, it will invoke B, which also prints with Cconws. |>Before B is called, the user has the option of redirecting B's |>output anywhere (screen, printer, file, modem). After B runs, control is |>returned to A, which will then continue printing to the screen as before. Here is what I use in Arcgsh for io redirection to call Zoo (hence some names) as a dependend program (partly cited). "zoo_stdin" and "zoo_stdout" are filenames, the "...descriptors" are ints, STDIN is 0 and STDOUT is 1. /* redirect standard input: */ save_stdin_descriptor = Fdup (STDIN); my_stdin_descriptor = Fopen (zoo_stdin, 0); if (my_stdin_descriptor >= 0) Fforce (STDIN, my_stdin_descriptor); /* redirect standard output: */ save_stdout_descriptor = Fdup (STDOUT); if (append_to_stdout_file) { my_stdout_descriptor = Fopen (zoo_stdout, 2); if (my_stdout_descriptor >= 0) Fseek (0L, my_stdout_descriptor, 2); else my_stdout_descriptor = Fcreate (zoo_stdout, 0); } else my_stdout_descriptor = Fcreate (zoo_stdout, 0); if (my_stdout_descriptor >= 0) Fforce (STDOUT, my_stdout_descriptor); /* call the program now... */ /* undo the redirections: */ Fforce (STDIN, save_stdin_descriptor); Fclose (my_stdin_descriptor); Fforce (STDOUT, save_stdout_descriptor); Fclose (my_stdout_descriptor); Dipl.-Inform. Rainer Klute klute@heike.informatik.uni-dortmund.de Univ. Dortmund, IRB klute@unido.uucp, klute@unido.bitnet Postfach 500500 |)|/ ...uunet!mcvax!unido!klute D-4600 Dortmund 50 |\|\ Tel.: +49 231 755-4663