[SPARK-13670][LAUNCHER] Propagate error from launcher to shell.
[SPARK-13670][LAUNCHER] Propagate error from launcher to shell.

bash doesn't really propagate errors from subshells when using redirection
the way spark-class does; so, instead, this change captures the exit code
of the launcher process in the command array, and checks it before executing
the actual command.

Tested by injecting an error in Main.java (the launcher entry point) and
verifying the shell gets the right exit code from spark-class.

Author: Marcelo Vanzin <vanzin@cloudera.com>

Closes #12910 from vanzin/SPARK-13670.

publicRoman/spark,ioana-delaney/spark,aokolnychyi/spark,publicRoman/spark,rikima/spark,ericvandenbergfb/spark,ahnqirage/spark,narahari92/spark,joseph-torres/spark,rekhajoshm/spark,nlalevee/spark,facaiy/spark,rednaxelafx/apache-spark,saturday-shi/spark,ericvandenbergfb/spark,dhruve/spark,mike0sv/spark,nilsgrabbert/spark,apache-spark-on-k8s/spark,goldmedal/spark,huang1900/spark,dhruve/spark,MLnick/spark,lxsmnv/spark,ahnqirage/spark,holdenk/spark,aray/spark,zuotingbing/spark,JoshRosen/spark,bdrillard/spark,rekhajoshm/spark,markhamstra/spark,jlopezmalla/spark,zuotingbing/spark,dbtsai/spark,sureshthalamati/spark,mdespriee/spark,markhamstra/spark,kissmetrics/spark,rednaxelafx/apache-spark,esi-mineset/spark,1haodian/spark,nchammas/spark,Aegeaner/spark,map222/spark,stanzhai/spark,BryanCutler/spark,holdenk/spark,nilsgrabbert/spark,cin/spark,HyukjinKwon/spark,lxsmnv/spark,saturday-shi/spark,kissmetrics/spark,hhbyyh/spark,someorz/spark,mahak/spark,panfengfeng/spark,lvdongr/spark,ConeyLiu/spark,ptkool/spark,maropu/spark,lxsmnv/spark,LantaoJin/spark,ericvandenbergfb/spark,WeichenXu123/spark,1haodian/spark,kissmetrics/spark,xflin/spark,caneGuy/spark,actuaryzhang/spark,matthewfranglen/spark,panfengfeng/spark,maropu/spark,aray/spark,lvdongr/spark,hvanhovell/spark,xflin/spark,shuangshuangwang/spark,sureshthalamati/spark,rezasafi/spark,saturday-shi/spark,highfei2011/spark,andrewor14/spark,bOOm-X/spark,ddna1021/spark,loneknightpy/spark,chuckchen/spark,spark-test/spark,adrian-ionescu/apache-spark,sahilTakiar/spark,kimoonkim/spark,joseph-torres/spark,srowen/spark,dhruve/spark,ddna1021/spark,metamx/spark,wangmiao1981/spark,wangyum/spark,someorz/spark,bravo-zhang/spark,ddna1021/spark,someorz/spark,jiangxb1987/spark,nchammas/spark,debugger87/spark,tejasapatil/spark,bdrillard/spark,map222/spark,stanzhai/spark,nlalevee/spark,jianran/spark,tengpeng/spark,rednaxelafx/apache-spark,actuaryzhang/spark,joseph-torres/spark,rednaxelafx/apache-spark,tengpeng/spark,WindCanDie/spark,wzhfy/spark,mzl9039/spark,byakuinss/spark,icexelloss/spark,cloud-fan/spark,bravo-zhang/spark,aosagie/spark,narahari92/spark,kevinyu98/spark,stanzhai/spark,nchammas/spark,bdrillard/spark,hvanhovell/spark,cloud-fan/spark,ibm-research-ireland/sparkoscope,ahnqirage/spark,sahilTakiar/spark,holdenk/spark,zhouyejoe/spark,JoshRosen/spark,skonto/spark,rikima/spark,brad-kaiser/spark,lvdongr/spark,sureshthalamati/spark,nilsgrabbert/spark,aokolnychyi/spark,LantaoJin/spark,eyalfa/spark,Panos-Bletsos/spark-cost-model-optimizer,SHASHANKB/spark,jlopezmalla/spark,alunarbeach/spark,wangmiao1981/spark,big-pegasus/spark,goldmedal/spark,pgandhi999/spark,andrewor14/spark,spark-test/spark,guoxiaolongzte/spark,huang1900/spark,minixalpha/spark,alunarbeach/spark,SHASHANKB/spark,brad-kaiser/spark,HyukjinKwon/spark,facaiy/spark,adrian-ionescu/apache-spark,adrian-ionescu/apache-spark,xflin/spark,michalsenkyr/spark,MLnick/spark,michalsenkyr/spark,JoshRosen/spark,rikima/spark,LantaoJin/spark,ajaysaini725/spark,dhruve/spark,caneGuy/spark,1haodian/spark,zero323/spark,alunarbeach/spark,highfei2011/spark,andrewor14/spark,MLnick/spark,pgandhi999/spark,wzhfy/spark,witgo/spark,shuangshuangwang/spark,lxsmnv/spark,pgandhi999/spark,shaneknapp/spark,shuangshuangwang/spark,nlalevee/spark,nlalevee/spark,shaneknapp/spark,joseph-torres/spark,ptkool/spark,stanzhai/spark,liyichao/spark,saltstar/spark,esi-mineset/spark,hhbyyh/spark,tengpeng/spark,cloud-fan/spark,yanboliang/spark,wangmiao1981/spark,JoshRosen/spark,saltstar/spark,ueshin/apache-spark,aokolnychyi/spark,sahilTakiar/spark,akopich/spark,saturday-shi/spark,dhruve/spark,publicRoman/spark,tejasapatil/spark,ioana-delaney/spark,caneGuy/spark,chuckchen/spark,lxsmnv/spark,dbtsai/spark,zhouyejoe/spark,icexelloss/spark,tejasapatil/spark,guoxiaolongzte/spark,taroplus/spark,1haodian/spark,zhouyejoe/spark,actuaryzhang/spark,setjet/spark,byakuinss/spark,nlalevee/spark,liyichao/spark,zzcclp/spark,Panos-Bletsos/spark-cost-model-optimizer,taroplus/spark,tengpeng/spark,vinodkc/spark,chuckchen/spark,sachintyagi22/spark,JoshRosen/spark,poffuomo/spark,actuaryzhang/spark,ibm-research-ireland/sparkoscope,rezasafi/spark,bOOm-X/spark,ericvandenbergfb/spark,lxsmnv/spark,BryanCutler/spark,narahari92/spark,liutang123/spark,mzl9039/spark,map222/spark,ptkool/spark,chuckchen/spark,poffuomo/spark,eyalfa/spark,rekhajoshm/spark,chuckchen/spark,techaddict/spark,wzhfy/spark,xuanyuanking/spark,nilsgrabbert/spark,saltstar/spark,witgo/spark,jlopezmalla/spark,minixalpha/spark,kevinyu98/spark,xflin/spark,milliman/spark,liyichao/spark,brad-kaiser/spark,ioana-delaney/spark,andrewor14/spark,markhamstra/spark,Aegeaner/spark,hvanhovell/spark,poffuomo/spark,sachintyagi22/spark,jlopezmalla/spark,kevinyu98/spark,janewangfb/spark,HyukjinKwon/spark,akopich/spark,saturday-shi/spark,saltstar/spark,ron8hu/spark,lvdongr/spark,esi-mineset/spark,jlopezmalla/spark,ron8hu/spark,janewangfb/spark,zuotingbing/spark,xuanyuanking/spark,lxsmnv/spark,michalsenkyr/spark,maropu/spark,shaneknapp/spark,yanboliang/spark,ueshin/apache-spark,JerryLead/spark,Aegeaner/spark,jianran/spark,kissmetrics/spark,janewangfb/spark,UndeadBaneGitHub/spark,nilsgrabbert/spark,poffuomo/spark,zzcclp/spark,HyukjinKwon/spark,caneGuy/spark,icexelloss/spark,milliman/spark,loneknightpy/spark,tejasapatil/spark,mike0sv/spark,MLnick/spark,kevinyu98/spark,ron8hu/spark,gengliangwang/spark,SnappyDataInc/spark,srowen/spark,mzl9039/spark,someorz/spark,xuanyuanking/spark,ibm-research-ireland/sparkoscope,andrewor14/spark,patrick-nicholson/spark,dbtsai/spark,jiangxb1987/spark,tejasapatil/spark,dhruve/spark,kiszk/spark,zero323/spark,wangyum/spark,huang1900/spark,goldmedal/spark,jiangxb1987/spark,loneknightpy/spark,ron8hu/spark,kevinyu98/spark,dbtsai/spark,actuaryzhang/spark,ConeyLiu/spark,techaddict/spark,ibm-research-ireland/sparkoscope,witgo/spark,metamx/spark,WeichenXu123/spark,mahak/spark,apache-spark-on-k8s/spark,zzcclp/spark,Panos-Bletsos/spark-cost-model-optimizer,goldmedal/spark,zuotingbing/spark,BryanCutler/spark,caneGuy/spark,liyichao/spark,szhem/spark,shubhamchopra/spark,gengliangwang/spark,minixalpha/spark,holdenk/spark,facaiy/spark,hvanhovell/spark,sachintyagi22/spark,narahari92/spark,jrshust/spark,sureshthalamati/spark,ueshin/apache-spark,nlalevee/spark,debugger87/spark,facaiy/spark,ptkool/spark,JoshRosen/spark,guoxiaolongzte/spark,mdespriee/spark,stanzhai/spark,cloud-fan/spark,stanzhai/spark,lvdongr/spark,shaneknapp/spark,debugger87/spark,UndeadBaneGitHub/spark,shubhamchopra/spark,sahilTakiar/spark,techaddict/spark,apache/spark,kevinyu98/spark,kiszk/spark,hhbyyh/spark,rekhajoshm/spark,LantaoJin/spark,WindCanDie/spark,zero323/spark,SnappyDataInc/spark,darionyaphet/spark,loneknightpy/spark,apache/spark,stanzhai/spark,WeichenXu123/spark,metamx/spark,byakuinss/spark,highfei2011/spark,tejasapatil/spark,mahak/spark,bravo-zhang/spark,jlopezmalla/spark,michalsenkyr/spark,lvdongr/spark,darionyaphet/spark,janewangfb/spark,jrshust/spark,ajaysaini725/spark,SHASHANKB/spark,dhruve/spark,JerryLead/spark,JerryLead/spark,eyalfa/spark,szhem/spark,witgo/spark,wzhfy/spark,adrian-ionescu/apache-spark,actuaryzhang/spark,mdespriee/spark,ericvandenbergfb/spark,tengpeng/spark,apache/spark,rikima/spark,witgo/spark,skonto/spark,alunarbeach/spark,aosagie/spark,1haodian/spark,bOOm-X/spark,mdespriee/spark,wangyum/spark,gengliangwang/spark,poffuomo/spark,bdrillard/spark,HyukjinKwon/spark,joseph-torres/spark,aray/spark,sachintyagi22/spark,guoxiaolongzte/spark,kevinyu98/spark,sachintyagi22/spark,liyichao/spark,wzhfy/spark,BryanCutler/spark,ajaysaini725/spark,BryanCutler/spark,guoxiaolongzte/spark,witgo/spark,bravo-zhang/spark,huang1900/spark,akopich/spark,LantaoJin/spark,big-pegasus/spark,shubhamchopra/spark,cin/spark,adrian-ionescu/apache-spark,LantaoJin/spark,yanboliang/spark,darionyaphet/spark,cin/spark,nchammas/spark,michalsenkyr/spark,apache-spark-on-k8s/spark,kiszk/spark,gengliangwang/spark,WeichenXu123/spark,hvanhovell/spark,saturday-shi/spark,goldmedal/spark,SHASHANKB/spark,BryanCutler/spark,WeichenXu123/spark,kimoonkim/spark,aosagie/spark,ibm-research-ireland/sparkoscope,wangmiao1981/spark,ueshin/apache-spark,srowen/spark,big-pegasus/spark,MLnick/spark,akopich/spark,highfei2011/spark,WeichenXu123/spark,rekhajoshm/spark,ConeyLiu/spark,ibm-research-ireland/sparkoscope,zero323/spark,map222/spark,apache-spark-on-k8s/spark,pgandhi999/spark,poffuomo/spark,esi-mineset/spark,bdrillard/spark,shubhamchopra/spark,kissmetrics/spark,spark-test/spark,brad-kaiser/spark,SHASHANKB/spark,WindCanDie/spark,cloud-fan/spark,milliman/spark,someorz/spark,liutang123/spark,map222/spark,yanboliang/spark,techaddict/spark,adrian-ionescu/apache-spark,jrshust/spark,saturday-shi/spark,HyukjinKwon/spark,nlalevee/spark,apache-spark-on-k8s/spark,dongjoon-hyun/spark,xuanyuanking/spark,dongjoon-hyun/spark,WindCanDie/spark,nchammas/spark,janewangfb/spark,taroplus/spark,ahnqirage/spark,shubhamchopra/spark,jrshust/spark,map222/spark,setjet/spark,michalsenkyr/spark,ioana-delaney/spark,markhamstra/spark,pgandhi999/spark,holdenk/spark,nchammas/spark,WeichenXu123/spark,patrick-nicholson/spark,shuangshuangwang/spark,techaddict/spark,panfengfeng/spark,patrick-nicholson/spark,zhouyejoe/spark,patrick-nicholson/spark,hvanhovell/spark,poffuomo/spark,panfengfeng/spark,eyalfa/spark,saltstar/spark,markhamstra/spark,lvdongr/spark,zero323/spark,someorz/spark,srowen/spark,goldmedal/spark,techaddict/spark,skonto/spark,mahak/spark,byakuinss/spark,andrewor14/spark,dongjoon-hyun/spark,setjet/spark,maropu/spark,wangmiao1981/spark,facaiy/spark,sahilTakiar/spark,dongjoon-hyun/spark,SnappyDataInc/spark,sachintyagi22/spark,icexelloss/spark,szhem/spark,zero323/spark,akopich/spark,milliman/spark,icexelloss/spark,skonto/spark,aosagie/spark,setjet/spark,panfengfeng/spark,narahari92/spark,mike0sv/spark,vinodkc/spark,wzhfy/spark,setjet/spark,zzcclp/spark,bOOm-X/spark,narahari92/spark,apache/spark,caneGuy/spark,jkbradley/spark,zuotingbing/spark,szhem/spark,icexelloss/spark,wangmiao1981/spark,WindCanDie/spark,HyukjinKwon/spark,patrick-nicholson/spark,srowen/spark,kimoonkim/spark,mdespriee/spark,JerryLead/spark,loneknightpy/spark,wangyum/spark,ddna1021/spark,bdrillard/spark,shubhamchopra/spark,rezasafi/spark,bOOm-X/spark,MLnick/spark,JerryLead/spark,brad-kaiser/spark,cin/spark,brad-kaiser/spark,ahnqirage/spark,byakuinss/spark,holdenk/spark,dongjoon-hyun/spark,andrewor14/spark,ddna1021/spark,aokolnychyi/spark,holdenk/spark,sahilTakiar/spark,panfengfeng/spark,jianran/spark,jianran/spark,rezasafi/spark,debugger87/spark,rekhajoshm/spark,rednaxelafx/apache-spark,ron8hu/spark,SnappyDataInc/spark,UndeadBaneGitHub/spark,ConeyLiu/spark,map222/spark,jianran/spark,jianran/spark,big-pegasus/spark,someorz/spark,actuaryzhang/spark,esi-mineset/spark,SnappyDataInc/spark,spark-test/spark,eyalfa/spark,debugger87/spark,brad-kaiser/spark,hvanhovell/spark,chuckchen/spark,sureshthalamati/spark,joseph-torres/spark,alunarbeach/spark,nilsgrabbert/spark,debugger87/spark,ueshin/apache-spark,rikima/spark,cin/spark,apache-spark-on-k8s/spark,kimoonkim/spark,hhbyyh/spark,jlopezmalla/spark,huang1900/spark,liutang123/spark,saltstar/spark,guoxiaolongzte/spark,mike0sv/spark,vinodkc/spark,kimoonkim/spark,taroplus/spark,cin/spark,shuangshuangwang/spark,huang1900/spark,dbtsai/spark,mdespriee/spark,kissmetrics/spark,highfei2011/spark,xuanyuanking/spark,jkbradley/spark,xflin/spark,skonto/spark,wangyum/spark,loneknightpy/spark,zhouyejoe/spark,panfengfeng/spark,liyichao/spark,ueshin/apache-spark,aosagie/spark,pgandhi999/spark,alunarbeach/spark,zuotingbing/spark,milliman/spark,kimoonkim/spark,kiszk/spark,patrick-nicholson/spark,vinodkc/spark,yanboliang/spark,Panos-Bletsos/spark-cost-model-optimizer,jrshust/spark,facaiy/spark,metamx/spark,aray/spark,joseph-torres/spark,zzcclp/spark,janewangfb/spark,skonto/spark,skonto/spark,SHASHANKB/spark,JoshRosen/spark,Aegeaner/spark,ron8hu/spark,jkbradley/spark,Aegeaner/spark,byakuinss/spark,UndeadBaneGitHub/spark,michalsenkyr/spark,patrick-nicholson/spark,rezasafi/spark,vinodkc/spark,bravo-zhang/spark,maropu/spark,liutang123/spark,1haodian/spark,sureshthalamati/spark,ajaysaini725/spark,debugger87/spark,mahak/spark,aray/spark,gengliangwang/spark,tejasapatil/spark,kiszk/spark,SnappyDataInc/spark,gengliangwang/spark,mahak/spark,jiangxb1987/spark,jkbradley/spark,jianran/spark,spark-test/spark,SHASHANKB/spark,liyichao/spark,darionyaphet/spark,milliman/spark,sureshthalamati/spark,publicRoman/spark,MLnick/spark,ajaysaini725/spark,kiszk/spark,ioana-delaney/spark,mdespriee/spark,jkbradley/spark,ptkool/spark,bOOm-X/spark,big-pegasus/spark,shuangshuangwang/spark,metamx/spark,wzhfy/spark,maropu/spark,akopich/spark,saltstar/spark,icexelloss/spark,xflin/spark,shubhamchopra/spark,mzl9039/spark,ericvandenbergfb/spark,zhouyejoe/spark,darionyaphet/spark,minixalpha/spark,srowen/spark,rednaxelafx/apache-spark,techaddict/spark,shuangshuangwang/spark,UndeadBaneGitHub/spark,Panos-Bletsos/spark-cost-model-optimizer,markhamstra/spark,narahari92/spark,jiangxb1987/spark,szhem/spark,zero323/spark,cloud-fan/spark,bravo-zhang/spark,gengliangwang/spark,shaneknapp/spark,aray/spark,nchammas/spark,minixalpha/spark,WindCanDie/spark,taroplus/spark,tengpeng/spark,caneGuy/spark,mzl9039/spark,eyalfa/spark,dbtsai/spark,aokolnychyi/spark,dbtsai/spark,shaneknapp/spark,rekhajoshm/spark,aokolnychyi/spark,vinodkc/spark,kimoonkim/spark,ron8hu/spark,jiangxb1987/spark,rednaxelafx/apache-spark,UndeadBaneGitHub/spark,tengpeng/spark,srowen/spark,ahnqirage/spark,apache/spark,aosagie/spark,metamx/spark,kissmetrics/spark,esi-mineset/spark,szhem/spark,dongjoon-hyun/spark,publicRoman/spark,pgandhi999/spark,alunarbeach/spark,chuckchen/spark,big-pegasus/spark,dongjoon-hyun/spark,ahnqirage/spark,markhamstra/spark,BryanCutler/spark,huang1900/spark,yanboliang/spark,ioana-delaney/spark,Panos-Bletsos/spark-cost-model-optimizer,witgo/spark,rikima/spark,maropu/spark,nilsgrabbert/spark,cin/spark,wangmiao1981/spark,rezasafi/spark,mike0sv/spark,milliman/spark,eyalfa/spark,JerryLead/spark,bOOm-X/spark,taroplus/spark,janewangfb/spark,liutang123/spark,mike0sv/spark,aray/spark,ibm-research-ireland/sparkoscope,sahilTakiar/spark,kiszk/spark,liutang123/spark,UndeadBaneGitHub/spark,ConeyLiu/spark,aosagie/spark,highfei2011/spark,zuotingbing/spark,xuanyuanking/spark,SnappyDataInc/spark,taroplus/spark,apache-spark-on-k8s/spark,highfei2011/spark,ueshin/apache-spark,shaneknapp/spark,ajaysaini725/spark,hhbyyh/spark,ioana-delaney/spark,apache/spark,setjet/spark,metamx/spark,jrshust/spark,ericvandenbergfb/spark,mzl9039/spark,Aegeaner/spark,facaiy/spark,big-pegasus/spark,spark-test/spark,jkbradley/spark,darionyaphet/spark,minixalpha/spark,hhbyyh/spark,sachintyagi22/spark,ddna1021/spark,mzl9039/spark,jrshust/spark,ptkool/spark,jiangxb1987/spark,liutang123/spark,ConeyLiu/spark,spark-test/spark,LantaoJin/spark,wangyum/spark,ddna1021/spark,darionyaphet/spark,loneknightpy/spark,JerryLead/spark,minixalpha/spark,szhem/spark,vinodkc/spark,bravo-zhang/spark,rikima/spark,zhouyejoe/spark,bdrillard/spark,ConeyLiu/spark,zzcclp/spark,publicRoman/spark,setjet/spark,Aegeaner/spark,zzcclp/spark,aokolnychyi/spark,xuanyuanking/spark,Panos-Bletsos/spark-cost-model-optimizer,hhbyyh/spark,mahak/spark,ptkool/spark,apache/spark,jkbradley/spark,cloud-fan/spark,esi-mineset/spark,goldmedal/spark,guoxiaolongzte/spark,1haodian/spark,adrian-ionescu/apache-spark,mike0sv/spark,wangyum/spark,xflin/spark,publicRoman/spark,yanboliang/spark,ajaysaini725/spark,rezasafi/spark,akopich/spark,WindCanDie/spark,byakuinss/spark