commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paulo Roberto Massa Cereda <cereda.pa...@gmail.com>
Subject Re: [exec] Execution fails with quoted arguments
Date Tue, 29 Apr 2014 16:25:48 GMT
Hi Siegfried, hey guys!

Now I'm more puzzled after running the following test with ProcessBuilder:

**************************
@Test
public void testProcessBuilder() throws IOException {

     ProcessBuilder bibtex = new ProcessBuilder();
     bibtex.command(new String[]{"bibtex", "file with spaces.aux"});
     Process process = bibtex.start();

     InputStream inputStream = process.getInputStream();
     InputStreamReader inputStreamReader = new 
InputStreamReader(inputStream);
     BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
     String currentLine;
     while ((currentLine = bufferedReader.readLine()) != null) {
         System.out.println(currentLine);
     }

     try {
         int exitValue = process.waitFor();
         System.out.println(exitValue);
     } catch (InterruptedException e) { }
}
**************************

I got the expected execution! vvv

**************************

-------------------------------------------------------
  T E S T S
-------------------------------------------------------
Running cereda.tests.ProcessBuilderTest
This is BibTeX, Version 0.99d (TeX Live 2013)
The top-level auxiliary file: file with spaces.aux
The style file: plain.bst
Database file #1: master.bib
Warning--I didn't find a database entry for "with:1977"
(There was 1 warning)
0
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.61 sec

**************************

I'm really lost now. And it's still Tuesday, so no excuses for getting a 
beer today. :)

All the best,

Paulo

Em 28-04-2014 15:34, Siegfried Goeschl escreveu:
> Hi Paulo,
>
> I’m also a bit puzzled :-)
>
> 1) Can you remove the “.aux” extension when invoking “bibtex”?
> 2) Please check http://tex.stackexchange.com/questions/112606/how-to-make-space-recognized-in-bib-filename-when-setting-bibliography
>
> Cheers,
>
> Siegfried Goeschl
>
>
> On 24 Apr 2014, at 15:36, Paulo Roberto Massa Cereda <cereda.paulo@gmail.com> wrote:
>
>> Hello Siegfried,
>>
>>> sorry for the next dumb question (but I'm actually quite good at it)
>>
>> Don't say such thing, you are helping me a lot with these questions. :)
>>
>> There we go:
>>
>>> * what is the result of the failed "bibtex" invocation?
>>
>> The message prompted is
>>
>> -----------------
>> I couldn't open file name `"file with spaces.aux".aux'
>> -----------------
>>
>> And the program returns 1 as exit value.
>>
>> If I copy "file with spaces.aux" and rename it to "filewithnospaces.aux", I get
>>
>> -----------------
>> This is BibTeX, Version 0.99d (TeX Live 2013)
>> The top-level auxiliary file: filewithnospaces.aux
>> The style file: plain.bst
>> Database file #1: master.bib
>> Warning--I didn't find a database entry for "with:1977"
>> (There was 1 warning)
>> -----------------
>>
>> And the program returns 0 as exit value.
>>
>>> * is "bibtex" a native binary or a shell script?
>>
>> Native binary.
>>
>> paulo@alexandria ~$ file `which bibtex`
>> /opt/texbin/bibtex: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically
linked (uses shared libs), for GNU/Linux 2.6.9, stripped
>>
>>> * depending on the error - can you replace the "bibtex" with a shell
>>> script to dump the current working directory - sometime the things
>>> are not executing where you expect them (just battled Java-native
>>> launchers where the current working directory can't be set
>>
>> I replaced bibtex with a script that prints $PWD and the provided arguments. I got
>>
>> Current directory ($PWD):
>> /home/paulo/Projetos/commons-exec-report
>>
>> Arguments:
>> "file with spaces.aux"
>> Done.
>>
>> with 0 as exit value.
>>
>> Quite odd, isn't it? :) It's driving me crazy. Well, crazier. :P
>>
>> All the best,
>>
>> Paulo
>>
>> Em 24-04-2014 10:14, Siegfried Goeschl escreveu:
>>> Hi Pauolo,
>>>
>>> sorry for the next dumb question (but I'm actually quite good at it)
>>>
>>> * what is the result of the failed "bibtex" invocation?
>>>
>>> * is "bibtex" a native binary or a shell script?
>>>
>>> * depending on the error - can you replace the "bibtex" with a shell
>>> script to dump the current working directory - sometime the things are
>>> not executing where you expect them (just battled Java-native launchers
>>> where the current working directory can't be set
>>>
>>> Cheers,
>>>
>>> Siegfried Goeschl
>>>
>>> On 24.04.14 15:07, Paulo Roberto Massa Cereda wrote:
>>>> Hello Siegfried!
>>>>
>>>> Wow, thanks for the fast response. :)
>>>>
>>>> Deeply sorry, I forgot to mention the environment. I'm running my code
>>>> under Linux (Fedora 20, Java 1.7.0) and MacOSX (Mavericks, 10.9.2). I
>>>> was unaware of the .aux thing under Windows, it's good to know about it;
>>>> TeX tools use .aux files all the time, so it might be interesting to
>>>> investigate some side effects from it. :)
>>>>
>>>> Apparently, the error persists with other tool named makeglossaries that
>>>> also uses this .aux file. I'm starting to get scared. :)
>>>>
>>>> All the best,
>>>>
>>>> Paulo
>>>>
>>>> Em 24-04-2014 09:50, Siegfried Goeschl escreveu:
>>>>> Hi Paulo,
>>>>>
>>>>> some stupid thought and it might not even be related to your problem
>>>>>
>>>>> "aux" is under Windows a reserved and can't be used as file name - see
>>>>> http://en.wikipedia.org/wiki/Filename - are you running the stuff under
>>>>> WIndows?
>>>>>
>>>>> Is it possible to rename the offending file to something different then
>>>>> ".aux"
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Siegfried Goeschl
>>>>>
>>>>> On 24.04.14 14:36, Paulo Roberto Massa Cereda wrote:
>>>>>> 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: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>
>>>>>
>>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message