#!/usr/bin/python # fileDes3.py redirecting output in child import os, sys def main(): fileNm = raw_input('Enter the output file name: '); try: chPID = os.fork() if chPID > 0: print 'In parent' os.waitpid(chPID,0) print 'Child', chPID, 'ends' else: print 'In child' try: os.close(sys.stdout.fileno()) except: OSError print "os.close() fails" try: os.open(fileNm, os.O_CREAT+os.O_WRONLY) except: OSError print "os.open() fails" print "Again in child" except: OSError print "fork() fails" main()