ignac@electro.UUCP (Ignac Kolenko) (04/10/90)
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. So the question i ask is: what is the proper way for A to redirect B's output before B is invoked. Or is this even the correct way of thinking about this problem. Any comments, code fragments, etc will be happily accepted and graciously rewarded with thanx at this time! -- =====Ignac A. Kolenko (The Ig)=====watmath!watcgl!electro!brasoft!ignac====== co-author of QuickST, and the entire line of Quick Software!!!! Branch Always Software Box 2624, Station B, Kitchener, Ont. CANADA N2H 6N2 =============================================================================
klute@heike.informatik.uni-dortmund.de (Rainer Klute) (04/11/90)
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