use IPC::Open2 qw( open2 ); use IPC::Open3 qw( open3 ); # this works: my $kid = open(FH1, "java -classpath $PATH TextEntry"); my $kid = open2(FH1, FH2, "java -classpath $PATH TextEntry"); my $kid = open3(FH1, FH2, FH3, "java -classpath $PATH TextEntry"); # however, when I try to suppress stderr, # it doesn't work because of the redirection, # and the process is launched it in a shell; # $kid is the pid of the shell: my $kid = open(FH1, "java -classpath $PATH TextEntry 2> /dev/null"); my $kid = open2(FH1, FH2, "java -classpath $PATH TextEntry 2> /dev/null"); # no problem, open3() will capture STDERR, taking # care of the redirection: my $kid = open3(FH1, FH2, FH3, "java -classpath $PATH TextEntry"); # however, the use IPC::Open2() docs # (to which IPC::Open3() is compared to) # indicates that the above form would be run in a shell, # so it may be safer to do this: my $kid = open3(FH1, FH2, FH3, "java", "-classpath", "$PATH", "TextEntry"); # but there is a way to capture the child output # using open() and still kill it when parent exits: # exec the command from the shell, thus # $kid = pid of shell = pid of the command # suggested by ikegami: my $kid = open(FH1, "exec java -classpath $PATH TextEntry 2> /dev/null");