in reply to Perl to Java
But if you really need to split it between the two, one simple way of passing things between a Java and a Perl program would be to use pipes. Assuming you are on Unix, that is.
If the perl program gets executed first, you could create a couple of pipes, fork a child process and execute the Java program there. Then the Java program can read from STDIN and write to STDOUT to communicate with your perl program. Something like this:
Something similar could be done if the Java program is the one that gets executed first, but my Java is too rusty to make an attempt at that.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"; }
--ZZamboni
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Perl to Java
by merlyn (Sage) on May 10, 2000 at 23:54 UTC | |
by pschoonveld (Pilgrim) on May 11, 2000 at 00:25 UTC | |
|