Example:
#!/bin/bash
set -x
_exs_argfile=argfile
_exs_errfile=errfile
_exs_outfile=outfile
rm -f "$_exs_argfile" "$_exs_errfile" "$_exs_outfile"
> "$_exs_argfile"
mkfifo "$_exs_errfile" "$_exs_outfile"
exiftool -stay_open True -@ "$_exs_argfile" 2> "$_exs_errfile" 1> "$_exs_outfile" &
pid=$!
# Why so complicated? -q ... would mute the {ready} label, so make sure it is always included with -echo3/4. Append \0 to simplify parsing binary data.
printf '%s%b%s\n\n' \
$'-ImageWidth\n-IllegalTag \nimg.tif\n-echo3\n{ready123}' \
'\0' \
$'\n-execute123' \
>> argfile
kill -CONT $pid &> /dev/null
DONE=
until [ $DONE ]; do
IFS= read -r -d '' line || DONE=1 # Separator \0 (accepting binary data)
echo "DEBUG: LINE FOUND"
# Parsing that may set DONE to 1
printf '%s' "$line"
[ ! $DONE ] && printf '%b' '\0'
done <"$_exs_outfile"
Content of the argfile (with NULL after {ready...}):
-ImageWidth
-IllegalTag
img.tif
-echo3
{ready123}
-execute123
I receive no output. "DEBUG: LINE FOUND" is never printed. What am I doing wrong? exiftool -@ argfile will output what I expect
Quote from: Andi on November 08, 2020, 01:21:57 PM
Content of the argfile (with NULL after {ready...}):
I don't understand. A NULL character in the argfile? I don't know what that would do.
- Phil
Quote from: Phil Harvey on November 08, 2020, 06:55:44 PM
Quote from: Andi on November 08, 2020, 01:21:57 PM
Content of the argfile (with NULL after {ready...}):
I don't understand. A NULL character in the argfile? I don't know what that would do.
- Phil
I want to accomplish several things:
- Let me know when the result is ready even if I use
-q.
- Let me parse binary data (although this seems to very slow compared to a normal exiftool call): This clashes with Bash's use of the NULL character as string delimiter. So I split the stream by NULL when parsing. To simplify finding the end label (that I provide for myself with
-echo...) I append NULL.
I get no result as well if I replace
printf ... by
echo $'-ImageWidth\n'"$1"$'\n-execute\n' >> "$_exs_argfile" and
read ... by
IFS= read -r line || DONE=1Anyway, I will try the same with files, I haven't managed it until now to stop parsing a FIFO, and to continue with the next request.