pipe RDRPARENT, WRTCHILD or die "Error: $!\n"; pipe RDRCHILD, WRTPARENT or die "Error: $!\n"; if (defined($pid=fork)) { if ($pid) { # In the parent # Close child's ends of the pipes close(WRTCHILD); close(RDRCHILD); # Continue, reading from RDRPARENT and writing to # WRTPARENT to communicate with the Java program. } else { # In the child # Close parent's ends of the pipe close(WRTPARENT); close(RDRPARENT); # Redirect STDOUT and STDIN to the pipes. open(STDOUT, ">&WRTCHILD") or die "Error: $!\n"; open(STDIN, "<&RDRCHILD") or die "Error: $!\n"; # Execute the java program exec("java prog.class"); die "Exec error: $!\n"; } } else { die "Fork error: $!\n"; }