Dear friends,
For some time, I was sure issue #54
(https://issues.apache.org/jira/browse/EXEC-54) was the culprit of one
my programs misbehaving. Today, I decided to devote some time in
understanding what's been happening in my code and apparently issue #54
does not appear to be culprit here!
Here's a sample code that might explain what's happening. Note that I
use two programs here (pdflatex and bibtex, hopefully available from any
recent TeX distribution), and similar expansions lead to different
results. Apologies for the long code excerpt.
===============================================================
@Test
public void testCommonsExecExecution() throws IOException,
InterruptedException {
String program = "bibtex";
String argument = "file with spaces.aux";
CommandLine line = new CommandLine(program);
line.addArgument(argument);
// so far, everything ok
assertEquals(line.toString(), "[bibtex, \"file with
spaces.aux\"]");
DefaultExecuteResultHandler resultHandler = new
DefaultExecuteResultHandler();
ByteArrayOutputStream out = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(streamHandler);
executor.execute(line, resultHandler);
resultHandler.waitFor();
// bibtex is executed with "file with spaces.aux".aux,
// which is not what I expected
assertEquals(out.toString(), "I couldn't open file name `\"file
with spaces.aux\".aux'\n");
program = "pdflatex";
argument = "file with spaces.tex";
line = new CommandLine(program);
line.addArgument(argument);
// so far, everything ok
assertEquals(line.toString(), "[pdflatex, \"file with
spaces.tex\"]");
resultHandler = new DefaultExecuteResultHandler();
out = new ByteArrayOutputStream();
streamHandler = new PumpStreamHandler(out, out);
executor = new DefaultExecutor();
executor.setStreamHandler(streamHandler);
executor.execute(line, resultHandler);
resultHandler.waitFor();
// here, pdflatex works with "file with spaces.tex"
assertTrue(out.toString().contains("! I can't find file `\"file
with spaces.tex\"'."));
}
===============================================================
Note that Exec has both
[ bibtex, file with spaces.aux ]
[ pdflatex, file with spaces.tex ]
parsed correctly, but only the latter execution is properly done. Now
I'm not sure if it's even Exec's fault, but what strikes me is the fact
that with pdflatex, the execution works.
Maybe I'm missing something obvious. Could you guys shed some light into
this problem?
All the best,
Paulo
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]