Aelfhere
Aelfhere

Reputation: 171

capture perl output with java

Alright, I'll get into the meat of things straight away:

I want to run a perl script from a java app (via ProcessBuilder), which will then parse an html page and find out some required information. I then want to pass that information back to my java app, and display that information in a JTextArea.

My knowledge of perl is VERY limited. My original thought was to write this data to a txt file, and then read that file with my java program, which could then display it to JTextArea pretty easily. However, this seems like an ugly solution, compared to simply returning a string.

Please let me know if there is a better way to do this. perhaps a completely different method than what I'm thinking of. Thanks,

Aelfhere

Upvotes: 0

Views: 845

Answers (3)

m.genova
m.genova

Reputation: 377

when you use a ProcessBuilder you instantiate a Process Object it's java representation of a batch execution

Tipically you can hook process streaming via Java API.

Extracted from Process JAVA API:

  • abstract InputStream getErrorStream() Gets the error stream of the subprocess
  • abstract InputStream getInputStream() Gets the input stream of the subprocess
  • abstract OutputStream getOutputStream() Gets the output stream of the subprocess

If perl script write on standard output stream then you can read that output.

Generally, If process doesn't write on standard output stream then you cannot read it.

Upvotes: 0

Miserable Variable
Miserable Variable

Reputation: 28752

You can pass strings between processes only by using some type of inter-process communication: either a pipe or shared memory or using network.

Why can you not do in Java what you want to do in Perl?

Upvotes: 0

Rocky Pulley
Rocky Pulley

Reputation: 23301

I think you want something like this

Upvotes: 1

Related Questions