Re: SOLVED: problem escaping in exiftool using exec() macro command on Windows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: SOLVED: problem escaping in exiftool using exec() macro command on Windows

Bill Christens-Barry-2
Hi again Gabriel,

I went back and retried a few things and found a solution; it involved using

   \"

to enclose the substring

  <=

to wit:

  exec("cmd", "/c", "C/Windows/exiftool.exe -ImageDescription\"<=\"C:/USBstick1/ExampleText.txt C:/USBstick1/ExampleImage.tif");

I'm pretty sure was this one of the most obvious and early things I tried (late on a Friday night), so either I misremember or it must have had a typo.

Exiftool tag writing only returns text describing its success or failure at modifying the target image file, so I tried following up with reading the new tag value via:

  exec("cmd", "/c", "C/Windows/exiftool.exe -ImageDescription\"<=\"C:/USBstick1/ExampleText.txt C:/USBstick1/ExampleImage.tif");

I can invoke exiftool independently and see that the tag value has been written anew. But, oddly, I can't yet print the returned value to the Log window in ImageJ, even though the macro language doc indicates that the result of the exec() command is returned. This is also true if I explicitly assign the result returned from exec() to a string variable (e.g. str = exec(...)). I'm not sure why the success or failure result of writing the tag is printed to the ImageJ Log window, while the result returned upon reading that tag is not and is not assigned to a variable.

Bill

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: SOLVED: problem escaping in exiftool using exec() macro command on Windows

Fred Damen
Greetings,

The return value of the *system* 'exec' subroutine is an integer which
signifies if the command was able to be run, e.g., was there enough memory
allocated to read in the executable from the file system.  The *system*
'exec' system subroutine if successful does not return and is usually
wrapped by fork and and wait; the macro language handles this for you.
Technically the return value from the command is an integer that is
returned by the program's 'main' routine; this may be what is returned by
the macro interpreter exec command (I do not know).  What you are
interpreting as the output from the program is what the program writes to
stdin, or stderr in case of errors.  Output to stdin, and stderr, can be
obtained by the system 'popen' subroutine; Java has access to this, and I
assume that the macro exec command uses this to copy the stdin(stderr?) to
the Log window. I do not know how to do this in the IJ macro language.

Enjoy,

Fred

On Sat, August 15, 2020 12:32 pm, Bill Christens-Barry wrote:
...

> I can invoke exiftool independently and see that the tag value has been
> written anew. But, oddly, I can't yet print the returned value to the Log
> window in ImageJ, even though the macro language doc indicates that the
> result of the exec() command is returned. This is also true if I
> explicitly assign the result returned from exec() to a string variable
> (e.g. str = exec(...)). I'm not sure why the success or failure result of
> writing the tag is printed to the ImageJ Log window, while the result
> returned upon reading that tag is not and is not assigned to a variable.
>
> Bill
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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