-stay_open fills out file with null bytes (from second command)

Started by Andi, November 13, 2020, 06:22:22 PM

Previous topic - Next topic

Andi

I created the following example to find out what exiftool will write into my outfile when using -stay_open:

#!/bin/bash

LB=$'\n'

> argf
> outf
> errf
exiftool -stay_open True -@ argf 2> errf 1> outf &
_exb_pid=$!

> argf
> outf
> errf
_exb_transactid="$(jot -r 1 100000000 999999999)"
printf '%s\n' -G >> argf
printf '%s\n' "img.jpg" >> argf
echo "-execute${_exb_transactid}
" >> argf
kill -CONT $_exb_pid &> /dev/null
sleep 1
cat outf

echo ...
#> argf <-- Important not to reset, else no output
> outf # <-- Reset out and error file to be able to output the current content while only stripping the trailing '{ready...}'
> errf
_exb_transactid="$(jot -r 1 100000000 999999999)"
printf '%s\n' -G >> argf
printf '%s\n' "img.jpg" >> argf
echo "-execute${_exb_transactid}
" >> argf
kill -CONT $_exb_pid &> /dev/null
sleep 1
cat outf

echo "-stay_open
False
" >> argf


I reset the outfile after the first command to be able to simply output the file, and it should not contain the results of the previous commands. But I can see that the outfile contains the following after the second command:

Quote\0\0....
RESULT OF SECOND COMMAND

The exiftool output of the following commands seem to include a replacement of the previous results by the same number of NULL bytes, and so the outfile will grow with each command which is not what I would expect. How can I keep the file small without using FIFOs ( https://exiftool.org/forum/index.php?topic=11799.0 )?

Andi

Solution:

exiftool -stay_open True -@ argf 2>> errf 1>> outf &