You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by 122jxgcn <yw...@gmail.com> on 2012/08/22 13:18:51 UTC
Runtime.exec() not working on Tomcat
I have following code on my Apache Tika Maven project.
This code works when I test locally, but fails when it's attached as
external jar in Apache Solr (container is Tomcat).
String cmd; contains command string that will convert file with input as
./convert.bin input.custom output.xml
I checked that convert.bin and input.custom exists.
String cmd; // As explained above
File out = new File(dir_path, output.xml); // dir_path is file path
Process ps = null;
try {
ps = Runtime.getRuntime().exec(cmd); // execute command
int exitVal = ps.waitFor();
logger.info("Executing Runtime successful with exit value of " +
exitVal);
// exitVal is 0
} catch (Exception e) {
logger.error("Exception in executing Runtime: " + e); // not reaching
here
}
// I get "Out file does not exist", although I should get the proper output
if (out.exists()) logger.info("Out file exists]");
else logger.info("Out file does not exist]"); // reaches here
out.setWritable(true);
out.setReadable(true);
out.setExecutable(true);
out.deleteOnExit();
// I get FileNotFoundException here
InputStream xml_stream = new FileInputStream(out);
I'm really confused because I get the right result locally (Maven test), but
not when it is on Tomcat.
Any help please?
--
View this message in context: http://lucene.472066.n3.nabble.com/Runtime-exec-not-working-on-Tomcat-tp4002614.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Runtime.exec() not working on Tomcat
Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Could it be different 'current' working directories? What happens if
you hardcode the full path into the command and input/output files?
./convert.bin -> /Dev/Solr/bin/convert.bin, etc.
Also, you may want to use some file system observation tools to figure
out exactly what file is touched where. Look for dtrace on Unix-like
systems and for SysInternals ProcMon on Windows.
Regards,
Alex.
Personal blog: http://blog.outerthoughts.com/
LinkedIn: http://www.linkedin.com/in/alexandrerafalovitch
- Time is the quality of nature that keeps events from happening all
at once. Lately, it doesn't seem to be working. (Anonymous - via GTD
book)
On Wed, Aug 22, 2012 at 7:18 AM, 122jxgcn <yw...@gmail.com> wrote:
> I have following code on my Apache Tika Maven project.
>
> This code works when I test locally, but fails when it's attached as
> external jar in Apache Solr (container is Tomcat).
>
> String cmd; contains command string that will convert file with input as
>
> ./convert.bin input.custom output.xml