0

For a single script redirecting stdout and stderr to a file with this:

./myscript.sh 2>&1 | tee -a out_file

works fine. When I try to run the same way a script containing multiple dialog boxes created with dialog command (and calling other scripts)

./main.sh 2>&1 | tee -a out_file

the out_file contains unwanted characters due to these boxes. For example:

#!/bin/bash
# myscript.sh

dialog --title "Title" \
--msgbox "Message Box" \
30 120
date 

generates with:

$ ./myscript.sh 2>&1 | tee -a myscript.out

multiple lines similar to this one:

[36m[44m  [30m[40m[K[22;38H[39;49m(B[m[2;3H[30m[47mMessage Box[22;38H[39;49m(B[m

How can I get stdout and stderr without these characters (for main and all subsequent scripts)? That would be in the example the output of date. Nice to have would be what a user has entered in an inputbox.

3
  • you could use tr to get rid of it like tr -d 'ﮛ' so maybe like ./main.sh 2>&1 | tr -d 'ﮛ' | tee -a out_file
    – barlop
    Commented Apr 6, 2018 at 17:55
  • We need details of the scripts and the unwanted characters. Please expand your question to include them.
    – AFH
    Commented Apr 6, 2018 at 18:00
  • Try using dialog --stdout option, dialog --stdout ...
    – Paulo
    Commented Apr 7, 2018 at 5:15

1 Answer 1

0

You're trying to log color-coded output into a file. See colors and formatting in bash: https://misc.flogisoft.com/bash/tip_colors_and_formatting

You can not arbitrarily change the stdout in this case. Because if you optimize the stdout for logging, then you also change the output wath the users sees.

But you have some possibilities:

  • The easiest way is to add in your myscript.sh the command echo "Message Box printed" >> myscript.out to record some actions directly in file.

  • You can try ./myscript.sh 2>&1 | sed -e "s/<your regex>//g" | tee -a myscript.out and replace <your regex>. But this change output too. So I think that's not what you're looking for.

  • Or you create your own descriptor in myscript.sh with echo "Exit code: $? Textbox $usertext" 1>&4 and modify the dialog command like this usertext=$(dialog --title "Title" --inputbox "Enter your text:" 30 120 "My Text" 3>&1 1>&2 2>&3) Then you can use . myscript.sh 4>> myscript.out

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .