检查程序中的错误代码 - 特别是 HTK Toolkit

发布于 2024-11-02 08:00:54 字数 685 浏览 0 评论 0原文

我有一个 bash 脚本,它调用 HTK 组件(例如 HCopyHVite)来计算一段文本的音素级别边界。如何检查操作是否成功?我已尝试以下操作:

  1. ./findWordBoundary.sh ; |& tee run.log

上面的方法不起作用。 HTK 实用程序输出的所有内容都会写入 run.log(错误语句和条件除外)。因此,在 run.log 上使用 grep 是行不通的。

  1. x=./findWordBoundary.sh 也不起作用。它只是将除错误条件之外的全部消息转储到 x 上。

我正在寻找的是这样的:
当 HTK 操作导致错误时记录并采取适当操作的方法。另外,我想这可以扩展到更通用的 bash 实用程序,例如 wget。如何从脚本中记录来自 bash 实用程序的日志和错误并对其进行处理(例如,当 wget 返回 404:Notfound 异常 时)?

谢谢,
斯里拉姆。

I have a bash script that calls HTK components such as HCopy and HVite to compute the phone level boundaries of a piece of text. How can I check if the operation was a success? I have tried the following:

  1. ./findWordBoundary.sh <input args> |& tee run.log

The above approach does not work. Everything that is output by the HTK utilities is written to run.log, except the Error statement and condition. So using grep on run.log is a non-starter.

  1. x=./findWordBoundary.sh <input args> also does not work. It just dumps a whole load of messages, apart from the error conditions, onto x.

What I am looking for is this:
A way to log, and take appropriate action, when HTK operations result in errors. Also, I guess this can be extended to more general bash utilities, like, say, wget. How does one log and error from a bash utility and handle it, from within a script (say when wget returns a 404:Not found exception)?

Thanks,
Sriram.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上青苔 2024-11-09 08:00:54

一般来说,Unix/Linux 命令完成并“发出”退出代码。成功的标准值为 0,错误的标准值为非零。

如果您设置了 HTcopy,您可以看到您的 HT 工具是否发出正确形成的退出代码,这样

HTcopy ... (args ) ...
echo $?

您就知道应该收到错误并且 echo $? 返回非零,然后检查设置是否正确命令args发出0。

如果您获得正确的退出代码,您可以像这样编写代码

if HTcopy .. (args).. ; then
   printf "do the next step\n"
   #etc
else
   printf "error on HTcopy, can't continue\n"
   exit 1
fi

另一个idom是将退出代码捕获到变量

HTcopy ... (args ) ...
h_rc=$?
if [[ ${h_rc} != 0 ]]] ; then
   printf "error on HTcopy, can't continue\n"
   exit 1
fi

此外,std Unix/Linux使用两个单独的消息流。 STDOUT 是正常消息和成功消息所在的位置,而 STDERR 是错误消息所在的位置。您可以通过将 STDERR 消息重定向到 STDOUT 流来捕获它们。使用上面的示例,其中“grep 是不可能的”,您可以这样做,

./findWordBoundary.sh <input args> 2>&1 |& tee run.log

我希望这会有所帮助。

In general, Unix/Linux commands finish and 'emit' an exit code. The standard value for success is 0, and non-zero for errors.

You can see if your HT tools are emitting correctly formed exit codes like this

HTcopy ... (args ) ...
echo $?

if you setup your HTcopy so you know you should get an error AND the echo $? returns non-zero then check that a good set of command args emit 0.

If you are getting correct exit codes, you can write your code like

if HTcopy .. (args).. ; then
   printf "do the next step\n"
   #etc
else
   printf "error on HTcopy, can't continue\n"
   exit 1
fi

Another idom is to capture the exit code to a variable

HTcopy ... (args ) ...
h_rc=$?
if [[ ${h_rc} != 0 ]]] ; then
   printf "error on HTcopy, can't continue\n"
   exit 1
fi

Also, std Unix/Linux uses two separate streams for messages. STDOUT is where normal messages and success message go, while STDERR is where error messages go. You can capture the STDERR msgs by redirecting them into the STDOUT stream. Using your example above where 'grep is a non-starter', you can do

./findWordBoundary.sh <input args> 2>&1 |& tee run.log

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文