On Feb 7, 9:40 am, wjharris...@optonline.net (Ice Man) wrote: > On Feb 7, 7:17 am, chas.ow...@gmail.com (Chas. Owens) wrote: > > > > > On Fri, Feb 6, 2009 at 14:31, Ice Man <wjharris...@optonline.net> wrote: > > > Ok ..... so I have to start a program which is written in java. > > > > #!/local/bin/perl > > > > my $command = "/aa/bb/c/executable \&"; > > > my $ret = 0; > > > > $ret = `$command`; > > > > exit $ret; > > > > The normal behavior of this executable is to list some information but > > > it never returns you to a prompt. You have to hit the return key to > > > get the shell prompt back. > > > > The same thing is happening to this program. Is there a way in perl > > > to pass a return "\n" on the command to be executed that would return > > > a prompt to the program so it does not hang? I have tried the > > > following: > > > snip > > > It sounds like you need IPC::Open2* or IPC::Open3**. They allow you > > to run an external command and control its STDIN, STDOUT, and, in the > > case of IPC::Open3, STDERR. Try something like this: > > > #!/usr/bin/perl > > > use strict; > > use warnings; > > > use IPC::Open2; > > > #if this is the child > > my $arg = shift; > > if (defined $arg and $arg eq 'you are the child') { > > print "I am the child\nwaiting for user to hit enter...\n"; > > <STDIN>; > > exit; > > > } > > > #if this is the parent > > print "I am the parent, getting ready to run the child\n"; > > #call myself with the argument "you are the child" > > open2 my $child_stdout, my $child_stdin, $0, "you are the child"; > > > print "child ran, sending return to it now\n"; > > #send a return to the child to get it to quit > > print $child_stdin "\n"; > > > #read what it wrote to the stdout > > print "child said:\n", map { "\t$_" } <$child_stdout>; > > > -- > > Chas. Owens > > wonkden.net > > The most important skill a programmer can have is the ability to read. > > Excellent !!! This looks like my answer! Will attempt to implement on > 09-Feb [Monday] and let you know. > > Thanks for your quick reply!
A bit of a quagmire here. Seems open2 /open3 are not available to me at work. A little frustrated here. Are there any other alternatives? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/