System.exit收益code未bash所检测到的eval [英] System.exit return code isn't detected by bash eval
问题描述
这个苦苦挣扎了一个小时... JAVA code:
ULogger.info(抛出666!);
System.exit(666);
bash的包装:
的eval $ {} COMMAND_TO_RUN
ret_ code = $?
printf的错误code:[%D]。$ {ret_ code}
输出:
[2012-11-30 15:20:12,971] [INFO]抛出666!
错误code:[0]
这里有什么交易?谢谢...
的 $ {COMMAND_TO_RUN}
是
((Java -Xmx9000m -Dtoday_nix = 20121128 -cp/ usr / lib目录/ Hadoop的/ conf目录com.paypal.risk.ars.linking.task_fw.BaseRunnableProcess 3>&安培; 1 1>和2 2 - ;和3)|三通的/ dev / TTY)GT; batches_errors.log
您的问题是在你的 COMMAND_TO_RUN
:
((Java -Xmx9000m -Dtoday_nix = 20121128 -cp/ usr / lib目录/ Hadoop的/ conf目录com.paypal.risk.ars.linking.task_fw.BaseRunnableProcess 3>&安培; 1 1>和2 2 - ;和3)|三通的/ dev / TTY)GT; batches_errors.log
被调用的最后一个节目是 T恤
,将与状态退出 0
,覆盖退出的Java值
。
您可以使用 $ PIPESTATUS
,这是返回值在管道的数组。
例如:
$猫nonexistantFile |呼应;回声E:$ P $ {PIPESTATUS [@]}
期望的输出:
E:0号码:1 0
猫
将失败(退出code 1),回声会成功(退出code 0)。 $?
将 0
。 $ {PIPESTATUS [0]}
将包含退出code为猫
( 1
)和 $ {PIPESTATUS [1]}
的一个回声( 0
)
struggling with this for an hour... java code:
ULogger.info("throwing out 666!");
System.exit(666);
bash wrapper:
eval ${COMMAND_TO_RUN}
ret_code=$?
printf "error code : [%d]" ${ret_code}
output:
[2012-11-30 15:20:12,971][INFO ] throwing out 666!
error code : [0]
what's the deal here? Thanks...
[EDIT]
The ${COMMAND_TO_RUN}
is
((java -Xmx9000m -Dtoday_nix=20121128 -cp "/usr/lib/hadoop/conf" com.paypal.risk.ars.linking.task_fw.BaseRunnableProcess 3>&1 1>&2 2>&3) | tee /dev/tty) > batches_errors.log
Your problem is in your COMMAND_TO_RUN
:
((java -Xmx9000m -Dtoday_nix=20121128 -cp "/usr/lib/hadoop/conf" com.paypal.risk.ars.linking.task_fw.BaseRunnableProcess 3>&1 1>&2 2>&3) | tee /dev/tty) > batches_errors.log
The last program called is tee
, which will exit with status 0
, overriding the exit
value of java
.
You can use $PIPESTATUS
, which is an array of return values in the pipe.
For example:
$ cat nonexistantFile | echo ; echo "e: $? p: ${PIPESTATUS[@]}"
Expected output:
e: 0 p: 1 0
cat
will fail (exit code 1), echo will succeed (exit code 0). $?
will be 0
.
${PIPESTATUS[0]}
will contain the exit code for cat
(1
) and ${PIPESTATUS[1]}
the one for echo (0
).
这篇关于System.exit收益code未bash所检测到的eval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!