Home > OS >  Not able to catch bash stderr on time
Not able to catch bash stderr on time

Time:08-17

I'm trying to extract all pages from a PDF to images using libvps available here: enter image description here

CodePudding user response:

This content was originally edited into the question by the OP.


I followed the corrective tool provided and this is my new code and it works well now. Thanks.

#!/bin/bash

DESTINATION="/home/user/my.pdf"
imagesStringPath="/home/user/my"
num_pgs=10

isEmpty(){
    _param="$1"
    if [[ -n "$_param" ]]; then
        echo "Output"
    else
        echo "No Output"
    fi
}

errorsArray=()
imagesStringPath="${DESTINATION%.pdf}"_
for (( i=0; i<=num_pgs; i   ))
do 
    #2>&1 to catch stderr to stdout
    OUT=$(vips copy ${DESTINATION}[page=$i,dpi=200] "$imagesStringPath$i".png 2>&1)
    echo "${OUT}";
    RETURN="$(isEmpty "$OUT")"
    if [ "$RETURN" = "Output" ]; then
        echo "${RETURN}";
        errorsArray =("$OUT")
    fi
done
#Check if no errors repotred by vips
echo "${#errorsArray[@]}"
  • Related