1

I have the following script in a bash script encode.sh.

echo "1 configuration out of 936"
x265 incident_10d_384x288_25.yuv --input-res 384x288 --fps 25 str/incident_10d_384x288_25_QP_0_ON_B0.bin --tune psnr --psnr --preset medium --max-merge 5 --merange 64 --no-open-gop -I 48 -i 8 --tu-intra-depth 3 --tu-inter-depth 3 --input-depth 8 --aq-mode 0 --b-adapt 0 --scenecut 48 --ref 4 --sao --deblock=0:0 --bframes 0 --qp 0 --csv-log-level 2 --log-level 4 --csv csv/incident_10d_384x288_25_QP_0_ON_B0.csv > txt/1_incident_10d_384x288_25_QP_0_ON_B0.txt 2<&1 
echo "2 configuration out of 936"
x265 incident_10d_384x288_25.yuv --input-res 384x288 --fps 25 str/incident_10d_384x288_25_QP_1_ON_B0.bin --tune psnr --psnr --preset medium --max-merge 5 --merange 64 --no-open-gop -I 48 -i 8 --tu-intra-depth 3 --tu-inter-depth 3 --input-depth 8 --aq-mode 0 --b-adapt 0 --scenecut 48 --ref 4 --sao --deblock=0:0 --bframes 0 --qp 1 --csv-log-level 2 --log-level 4 --csv csv/incident_10d_384x288_25_QP_1_ON_B0.csv > txt/2_incident_10d_384x288_25_QP_1_ON_B0.txt 2<&1 
echo "3 configuration out of 936"
x265 incident_10d_384x288_25.yuv --input-res 384x288 --fps 25 str/incident_10d_384x288_25_QP_2_ON_B0.bin --tune psnr --psnr --preset medium --max-merge 5 --merange 64 --no-open-gop -I 48 -i 8 --tu-intra-depth 3 --tu-inter-depth 3 --input-depth 8 --aq-mode 0 --b-adapt 0 --scenecut 48 --ref 4 --sao --deblock=0:0 --bframes 0 --qp 2 --csv-log-level 2 --log-level 4 --csv csv/incident_10d_384x288_25_QP_2_ON_B0.csv > txt/3_incident_10d_384x288_25_QP_2_ON_B0.txt 2<&1 

I want to write the output of each encoding from terminal to a txt file using > txt/3_incident_10d_384x288_25_QP_2_ON_B0.txt 2<&1. I create the bash script from windows using python 2.7 and I want to run it in ubuntu.

When I copy a line from bash script and run it in terminal it's working. But when I want to run it from batch file it's not working.

I get no error in terminal but the x265 encoder does not run with a warning:

[warning]: extra unused command arguments given <

Is there any special character in my shell script?

Do you know how to fix this?

zinon
  • 4,427
  • 14
  • 70
  • 112
  • 1
    I think you are looking for `2>&1`, to redirect standard error to the currently opened standard output. – chepner Oct 16 '17 at 11:44
  • what `2<&1`is supposed to do ? if you want to redirect stdout to stderr, that would be `1>&2`, or redirect stderr to stdout : `2>&1` – Pac0 Oct 16 '17 at 11:44

1 Answers1

2

Output redirection uses >&, not <&. That would be

2>&1 or 1>&2

(probably the first one, redirect standard error (2) to standard output (1) )

related question on Stack Overflow : How can I redirect and append both stdout and stderr to a file with Bash?


EDIT:

Apparently, you also had the error message in the other order :

[warning]: extra unused command arguments given >`

which is more surprising.

As per our small discussion in comments, it was due to incorrect line endings handling. Probably the whole script was seen as only one big line, which would explain that bash was surprised to see several redirections.

For information, in case comments get deleted : using Notepad++ menu Edit > EOL Conversion solved the issue. More info here : EOL conversion in notepad ++

Pac0
  • 21,465
  • 8
  • 65
  • 74
  • Thank you! I also have to copy and paste the code in the shell file in `ubuntu` server and not just copy/paste it. May some special characters from windows are also a potential problem. – zinon Oct 16 '17 at 11:52
  • @zinon I am not sure to understand your comment. Is that another problem you have ? In this case I recommend to open a new question with specific details. – Pac0 Oct 16 '17 at 11:54
  • Your proposed solution works only if I open the bash script in windows, copy the content and past it in a bash script file in linux. In case I drag and drop the bash script file from windows to linux, the problem still remains. – zinon Oct 16 '17 at 11:58
  • @zinon The same problem exactly? With the message `[warning]: extra unused command arguments given <` ? I am not aware of encoding problem turning `>` into `<`, I would recommend double checking you saved your file before drag&dropping it . – Pac0 Oct 16 '17 at 12:06
  • Yes, the same warning but having `>` instead of `<`. I double check it. I have a feeling that `"\n"` new line character after `2>&1 ` might be the problem. In any case, thank you for your help! – zinon Oct 16 '17 at 12:14
  • Newlines could be a problem indeed. How do you save / generate your scirpt file exactly ? Any decent text editor should have a function for end-of-lines (EOL) conversions. "Decent" means lots of them but **not Notepad.exe** :)) – Pac0 Oct 16 '17 at 12:17
  • You can try to play with line endings in the 'Edit > EOL conversion' menu to see if it solves your issue. – Pac0 Oct 16 '17 at 12:26
  • More info here : https://stackoverflow.com/questions/16239551/eol-conversion-in-notepad – Pac0 Oct 16 '17 at 12:32
  • Thank you for the tip! I will try it!! – zinon Oct 16 '17 at 12:35
  • 1
    You are right! `Edit > EOL conversion` solve my problem! – zinon Oct 16 '17 at 20:58