5.4.3 Standard-Device Redirection

A parent program can redirect a standard device for the child program by associating the standard-device handle with a new device or file before it starts the child program. To do this, the parent program should follow these steps:

1.Duplicate the standard-device handle by using Duplicate File Handle (Interrupt 21h Function 45h).

2.Save the duplicate handle.

3.Open the new file or device.

4.With the new handle retrieved in step 3, modify the standard-device handle by using Force Duplicate File Handle (Interrupt 21h Function 46h). The standard-device handle should now identify the same file or device as the new handle.

5.Load and run the child program.

A parent program can restore the original standard-device handle by using Force Duplicate File Handle and specifying the duplicate handle saved in step 2.