#!/usr/bin/python # namedPipe2.py creates a named pipe # $ ./namedPipe2.py r & # $ ./namedPipe2.py w & import os import sys def main(): try: os.mkfifo(sys.argv[2], 0666) except: OSError try: if sys.argv[1] == 'r': fd = os.open(sys.argv[2], os.O_RDONLY) data = os.read(fd, 100) print data elif sys.argv[1] == 'w': fd = os.open(sys.argv[2], os.O_WRONLY) os.write(fd, "\nWrittten in the named pipe") except: print 'wrong argument' main()