Login  Register

Re: bug report: -batch command adds txt extension and macros directory automatically

Posted by Carnë Draug on Mar 14, 2014; 5:01pm
URL: http://imagej.273.s1.nabble.com/bug-report-batch-command-adds-txt-extension-and-macros-directory-automatically-tp5006916p5006922.html

On 14 March 2014 15:59, Johannes Schindelin <[hidden email]> wrote:

> Hi Carnë,
>
> On Fri, 14 Mar 2014, Carnë Draug wrote:
>
>> 1) create a simple macro
>>
>> $ echo 'print ("Hello world!");' > ./macro_test
>>
>> 2) get an error from ImageJ about file not existing
>>
>> $ ImageJ-linux32 -batch macro_test
>>
>> Macro or script not found:
>>
>> $path for imagej$macros/macro_test.txt
>
> While you might argue that this is a bug, or that it is a bug that ImageJ
> looks into the current directory first before looking into the macros/
> directory when the file name contains no slash, by now it is an
> established API (application programmers' interface).
>
> Therefore I doubt that this bug -- if Wayne agrees that it is a bug -- can
> be fixed without seriously breaking existing workflows. And backwards
> compatibility is what Wayne states as one of his primary goals with ImageJ
> when you get the chance to listen to one of his presentations.

The bug is not limited to search into the macros folder first although
it would be nice if that was documented. The documentation states that
the "-batch" option takes path as argument [1] and a 20 years old bug
should not be made into a feature. But, I am sure everyone has seen
that happening for much worse cases, all in the name of backwards
compatibility, so I'm not going to argue with that (but please update
the documentation).

The bigger problem, which if fixed would not break backwards
compatibility, is that after looking into the macros directory with a
file extension that was never defined, it should at least check if the
given argument was the filepath all along. You will notice it still
looks into the current directory but with a file extension:

## this fails
$ echo 'print ("Hello world!");' > ./macro_test
$ ImageJ-linux32 -batch macro_test

## this works
$ echo 'print ("Hello world!");' > ./macro_test.txt
$ ImageJ-linux32 -batch macro_test

Experimenting with file extensions, this seems to be the behaviour:
1. looks into the macros directory with txt extension
2. looks into the macros directory with ijm extension
3. looks into the current directory with txt extension
4. fails because it doesn't find a file in current directory with txt

So there is a consistency problem as well because it does not try the
ijm file extension in the current directory. In addition, it doesn't
look for a file without file extension in the macros directory which
would be nice since after all, I specifically didn't specify a file
extension.

If before throwing an error, there is a check for a file named exactly
as it was meant in the input arguments and in the current working
directory, it would make it work as expected without breaking anyone's
code. This may still catch some people by surprise if a macro with the
same name happens to exist in the macros directory.

Carnë

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html