检查程序中的错误代码 - 特别是 HTK Toolkit
我有一个 bash 脚本,它调用 HTK
组件(例如 HCopy
和 HVite
)来计算一段文本的音素级别边界。如何检查操作是否成功?我已尝试以下操作:
./findWordBoundary.sh ; |& tee run.log
上面的方法不起作用。 HTK
实用程序输出的所有内容都会写入 run.log
(错误语句和条件除外)。因此,在 run.log
上使用 grep
是行不通的。
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:
./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.
x=./findWordBoundary.sh <input args>
also does not work. It just dumps a whole load of messages, apart from the error conditions, ontox.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,Unix/Linux 命令完成并“发出”退出代码。成功的标准值为 0,错误的标准值为非零。
如果您设置了 HTcopy,您可以看到您的 HT 工具是否发出正确形成的退出代码,这样
您就知道应该收到错误并且
echo $?
返回非零,然后检查设置是否正确命令args发出0。如果您获得正确的退出代码,您可以像这样编写代码
另一个idom是将退出代码捕获到变量
此外,std Unix/Linux使用两个单独的消息流。 STDOUT 是正常消息和成功消息所在的位置,而 STDERR 是错误消息所在的位置。您可以通过将 STDERR 消息重定向到 STDOUT 流来捕获它们。使用上面的示例,其中“grep 是不可能的”,您可以这样做,
我希望这会有所帮助。
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
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
Another idom is to capture the exit code to a variable
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
I hope this helps.