-v0 switch with -ver

Started by BogdanH, November 04, 2011, 12:50:26 PM

Previous topic - Next topic

BogdanH

Hi Phil,

In your documentation, there's written, that -v0 causes flushing output buffer after each line. But (if ExifTool is used in -stay_open mode), that doesn't seem to be the case for:
-v0 -ver -execute
That is, above command results two-line output:
8.68
{ready}

-but I believe, first output line (8.68) isn't flushed.
Now, if you will say, that I'm wrong on above, then that would mean, I'm doing something wrong with my piping (again).
But in case I'm right on above: are there other (known) cases, where line isn't flushed?

Bogdan

Phil Harvey

Hi Bogdan,

You are correct, but I am surprised that you can tell the difference since the time delay between these lines would be very short.

In the application, I enable the auto-flushing after all command-line arguments are parsed, so any output produced by parsing the arguments (ie. the -ver output) will not be flushed for each line.

Is this a problem for you?

In general, I don't think you can expect to receive one line at a time unless you can guarantee that you always process your input much faster than exiftool is sending it.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

BogdanH

#2
Hi Phil,

After reading your explanation, my "discovery" seems to be pure coincidence -and your last sentence opened my eyes (again).
Short explanation: In my code, I was trying to "optimize" catching {ready} line. And as it seems, when ExifTool is working with files, I can process incoming data fast enough to catch (almost?) each line. Obviously, when executing some "easy" task, like -ver command (flushed or not), it can be expected that ExifTool will be faster than readouts.
No, no problem at all -it disappeared right now  :)

Bogdan

Phil Harvey

#3
Hi Bogdan,

While we are on this topic, I should also mention the possibility of the opposite problem:  Reading only part of a line.

The steps you take should be as follows:

1) check to see if input is available (if necessary)

2) read the input

3) parse the input up to the newline character and handle this line in your code

4) repeat number 3 for all data read in step 2)

5) if there is any data after the last newline, save it then go back to number 1), adding any new input to complete this line

6) repeat the above until you see the "{ready}\n" message

- Phil

Edit: This assumes that you want to process each line as soon as it arrives, which it seems you are doing.  The alternative is to just accumulate all input data until it ends with a line matching "{ready}\n", then process it all together.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

BogdanH

Quote from: Phil Harvey on November 04, 2011, 04:44:11 PM
...the possibility of the opposite problem:  Reading only part of a line.
YES -that's exactly what happened when I started with stay_open stuff. But after you've mentioned {ready} being the last line (guaranteed), I've decided to read StdOut repetetive (into my buffer) until {ready} arrives. This way, I can pull data from StdOut really fast.
However, I can't apply exactly the same on reading from StdErr, because there isn't some "final" line sent from ExifTool -it would be much easer (and probably faster) for me, if there would be something I could catch on... Anyway, reading StdErr works now, I just need to make some further reliability tests (see your quote above). I know, I could redirect StdErr pipe to StdOut, but I prefer not to mix "regular" and "error" ExifTool data.

Quote..The alternative is to just accumulate all input data until it ends with a line matching "{ready}\n", then process it all together.
-as you can see, this is exactly what I'm doing with StdOut now.

Hopefully all this will end with something usefull  :)

Greetings,
Bogdan

Phil Harvey

#5
Hi Bogdan,

I understand now, thanks for explaining.

Waiting for "{ready}\n" on stdout then doing one final read on stderr should work unless you have queued multiple commands for exiftool to run on, in which case you may start getting output from the next command like this.

If you really need to synchronize the stdout and stderr streams you can take advantage of the undocumented -echo and -echo2 options which send output to stdout and stderr respectively.  But to do this, you need to execute an extra command so these outputs will come after the first command is complete.  For example:

...
-execute
-echo
{end4321}
-echo2
{end4321}
-execute


Here I have also used a serial number in the echo string that you could check to guarantee synchronization.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

BogdanH

Hi Phil,

Are you watching over my shoulder??  :)
As it seems, your suggestion is actually THE solution I was after: for StdOut and for StdErr.

I mean, I totally forgot about the possibility of having more than one -execute in command I send toward ExifTool! -and thus, the possibiliy there can be more than one {ready} in StdOut.

Thank you very much,
Bogdan

Phil Harvey

I'm glad I could help.  I am sort of excited about the idea of ExifToolGUI using the -stay_open feature because I think it will improve the response time significantly.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

I have just made the -echo and -echo2 options official by adding them to the documentation of ExifTool 8.69.

FYI: The -echo option has existed since version 6.86 (more than 4 years ago), and -echo2 was added in 8.41 (about a year ago).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

BogdanH

Thank you for reminding me about -echo... but even if -echo would be mentioned in your documentation before, I'm not sure if I would recognized it's usefullness for my case. You do remember giving me a hint about -v0 option? Same case: it was there all the time, but i didn't "see" it.

Now, let me see what's new in v8.69  :)

Bogdan