Hi Phil,
I am in the process of writing v2 of my Photoshop plugin (http://ps-scripting-experiments.blogspot.com/2010/07/save-jpeg-images-in-photoshop-without.html) to use exiftool to preserve makernotes while saving file via Photoshop.
This time I am using -stay_open option, and facing some problems.
exiftool is executed via
exiftool.exe" -stay_open True -@ "Temp\exifArgFile1316361233928.arg" 1>"Temp\exif-1316361233928.log" 2>"Temp\exif-1316361233928.err"
argument File:
-overwrite_original -tagsfromfile "F:\Temp\018.JPG" -exif:makerNotes "F:\Temp\018_Copy3.jpg"
-execute74424
It works, and exiftool stays open, it processes my commands (-ver\n-execute works). but for the above commands to copy exif tags I am getting an error
stdout file(.log):
{ready74424}
stderr file(.err):
File not found: mp/018.JPG" -exif:makerNotes "F:/Temp/018_Copy3.jpg"
As you can see argument file has whole command and file path. But for some reason exiftool complains about file not found, with part of the file path missing. Any ideas?
Yes. You have fallen into a common pitfall. It is one argument per line in the .args file, and you don't quote arguments, like this:
-overwrite_original
-tagsfromfile
F:\Temp\018.JPG
-exif:makerNotes
F:\Temp\018_Copy3.jpg
-execute74424
- Phil
thanks Phil.. After asking that question I saw "some options require additional arguments which must be placed on separate lines" in the documentation for @ flag. But wasn't sure what needs a new line and what not. So thank your for clarifying. I implemented your suggestion and now I have different issue
arg file:
#update exif for F:\Temp\018.JPG
-overwrite_original
-tagsfromfile
F:\Temp\018.JPG
-exif:makerNotes
F:\Temp\018_Copy1.jpg
-execute3878
stdout:
1 image files updated
1 files weren't updated due to errors
{ready3878}
stderr:
Error: File not found - ite_original
I checked target file and its updated for sure. But it did not remove the original file (018_Copy1.jpg_original).
It sounds like the _original file existed before you run the command. The -overwrite_original option won't erase an existing _original file.
When the documentation says "some options require additional arguments which must be placed on separate lines", it means that some options require additional arguments and all arguments must be placed on a separate line. The "some" is just because some options don't require additional arguments.
- Phil
Hi Phil, thank you very much for the response. Yes, now I understand the syntax. I wasn't sure about :makernotes part before I saw your example.
However _original issue is real, I tried with many files, mutiple times, exiftool create that _original file, but it does not remove it as evident by the error
Error: File not found - ite_original
For some reason first few characters are ignored, and thus the whole command/flag fails.
It looks like you could have an invisible character in your argfile between -overwr and ite_original.
Did you try re-generating the argfile?
- Phil
I generate the arg file on the fly in Photoshop extendScript (a variation of javascript)
//this step is executed once to create a new file
var ts = new Date().getTime();
var argFile = new File(Folder.temp + "/exifArgFile" +ts+".arg");
//this part is execute once per file, in a loop
var cmdText="";
cmdText=cmdText + "#update exif for " + sourceFile.fsName;
cmdText=cmdText + "\n-overwrite_original"
cmdText=cmdText + "\n-tagsfromfile";
cmdText=cmdText + "\n" + decodeURI (sourceFile.fsName) ;
cmdText=cmdText + "\n-exif:" + tags;
cmdText=cmdText + "\n" + decodeURI (targetFile.fsName) ;
argFile.open("w");
argFile.writeln(cmdText);
commandNumber=Math.floor(Math.random()*123456);
argFile.writeln("-execute" + parent.commandNumber);
argFile.close();
I'm afraid that I am at a loss here. I'm sure the problem isn't exiftool, but I can't think of another way that this could be happening. I suggesting trying variations of commands at your end and verifying that the output .args file is what you expect. ie) If you remove the comment line, what happens?
- Phil
I think the problem was with synchronization. I was writing to arg file in a loop while reading from stderr and etdout redirected files. And whole thing was running from temp files. So something was blocking exiftool from reading the arg file properly. I tried
exiftool.exe -stay_open true -@ exifArg.arg
in a command window, I manually wrote same commands via notepad++ and exiftool had no problems processing my commands.
I finally got my mechanism to working (after lot of trial and errors), and you won't belive what I finally got:
#update exif for F:\Temp\020.JPG
#
#
#
-ver
-overwrite_original
-tagsfromfile
F:\Temp\020.JPG
-exif:makerNotes
F:\Temp\020_Copy1.jpg
-execute58930
Those three comment lines did all the magic. Even if I put -ver in those line it errors out. with this setup log file is clean
8.64
1 image files updated
{ready58930}
I am using exiftool version number as kind of index mark, lastIndex(versionNumber) to lastIndex("{") gives me output for the current command. since the file redirected from stderr is locked by process I can not clean out that logfile.
Even exit command needs three blank line :)
#
#
#
-stay_open
False
Thank you helping out through this. When I started this work, I assumed exiftool to be 0% complexity since it always worked. I did not consider whole windows file/console management complexity :( Now since its working I can proceed to rest of the script
Your work-around is troubling since we still don't understand the problem.
There are many other people using the -stay_open feature in their Windows applications and none of them have reported a problem like this. I think the only difference in your case is that you're using the Photoshop extendScript.
Even if something blocks exiftool from reading the file it shouldn't cause a problem unless you are getting the error "Error reading from ARGFILE". ExifTool should just wait until it is able to read the file again. (That is, if you are using the -stay_open option. Without it, exiftool will stop reading the argfile when it encounters the EOF.)
If you could send me a version of the plug-in that gives you the error I can see if I can figure this out. My mail is philharvey66 at gmail.com
- Phil
Thanks Phil. I was adding some comments to send the files to you, and it stuck me. Instead of appending new commands (for copy, to exit etc) I was overwriting the comand file contents. Extendscript has a file object and has an open function. We can define the mode while opening the file.
fileObj.open (mode[,type][,creator])
mode A string indicating the read/write mode. One of:
w: (write) Opens a file for writing. If the file exists, [b]its contents are destroyed[/b]. If the file does not exist, creates a new, empty file.
e: (edit) Opens an existing file for reading and writing.
a: (append) Opens the file in Append mode, and moves the current position to the end of the file.
I was using "w" mode copied from first function where I create the arg file. I did not notice the contents destroyed part before. Only now I noticed "w" and contents part. I updated it to "e" mode and seek to end of the file before writing to it. Now it is working without any workarounds.
exiftool must be waiting to read from EOF position, and my new commands were going beyond EOF if I put those ### (or as many number of comment lines as many lines present in the command before). Had you not ask for these files I wouldn't have noticed it. Thanks a lot Phil.
This makes perfect sense. I should have thought of this but I am surprised you didn't notice yourself by looking at the .args file earlier.
Glad to have this problem solved.
- Phil
I missed the obvious. I did notice that my new commands were always started on first line, and I convinced myself that its like message queue, exiftool must be removing lines as it is processing files :)