Executing file inside Parser

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Executing file inside Parser

122jxgcn
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Executing file inside Parser

Nick Burch-2
On Thu, 2 Aug 2012, 122jxgcn wrote:
> I'm trying to execute binary file inside my custom parser.
> I put binary file on directory
>
> tika-parsers/src/main/resources/bin/hwp2xml.bin

Hmm, I'm not sure that'll work. The resources normally end up embedded in
the Jar, and most OS's don't know how to execute binaries from the middle
of a jar....

> and I'm doing something like on my parser
>
> if (!tstream.hasFile()) File f = tstream.getFile();
> Process ps = Runtime.getRuntime().exec("/bin/hwp2xml.bin", null, f);

I doubt that'll work. You should either put the binary outside of the jar,
or have a precurser step that extracts the resource out of a jar and puts
it into a temporary file that the OS can find to launch

Nick
Reply | Threaded
Open this post in threaded view
|

Re: Executing file inside Parser

David Meikle
In reply to this post by 122jxgcn
Hi,

On 2 Aug 2012, at 08:50, 122jxgcn <[hidden email]> wrote:

> I'm trying to execute binary file inside my custom parser.
> I put binary file on directory
>
> tika-parsers/src/main/resources/bin/hwp2xml.bin

Have you thought about using the External Parser support?  You can take a look at it in org.apache.tika.parser.external.ExternalParser[1].

From the file name it looks like you may be converting between formats to ease parsing but this could offer an alternative allowing you to map patterns for metadata and content extraction via the tika-external-parsers.xml[2] configuration file.

If it isn't a viable option, this is still a good example on how you could execute an external command using Tika, because as Nick's suggests you will need have this executable located externally or extract it outside the JAR.

Cheers,
Dave

[1] http://svn.apache.org/repos/asf/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/external/ExternalParser.java 
[2] http://svn.apache.org/repos/asf/tika/trunk/tika-parsers/src/main/resources/org/apache/tika/parser/external/tika-external-parsers.xml