Mac OS X 上的超时命令?
Mac OSx 上的超时命令有替代方法吗?基本要求是我能够在指定的时间内运行命令。
例如:
timeout 10 ping google.com
该程序在 Linux 上运行 ping 10 秒。
Is there an alternative for the timeout command on Mac OSx. The basic requirement is I am able to run a command for a specified amount of time.
e.g:
timeout 10 ping google.com
This program runs ping for 10s on Linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用
然后每当您需要超时时,请使用
.. 代替。为了解释为什么这里有一个来自自制警告部分的片段:
You can use
And then whenever you need timeout, use
..instead. To explain why here's a snippet from the Homebrew Caveats section:
另一种几乎可以跨平台工作的简单方法(因为它使用几乎无处不在的 perl)是这样的:
从这里抓取:
https://gist.github.com/jaytaylor/6527607
而不是将其放入函数中,您可以将以下行放入脚本中,它也会起作用:
timeout.sh
或内置帮助/示例的版本:
timeout.sh
Another simple approach that works pretty much cross platform (because it uses perl which is nearly everywhere) is this:
Snagged from here:
https://gist.github.com/jaytaylor/6527607
Instead of putting it in a function, you can just put the following line in a script, and it'll work too:
timeout.sh
or a version that has built in help/examples:
timeout.sh
正如kvz所述只需使用自制程序:
现在
timeout
命令已经可以使用 - 不需要别名(也不需要gtimeout
,尽管也可用)。As kvz stated simply use homebrew:
Now the
timeout
command is already ready to use - no aliases are required (and nogtimeout
required, although also available).您可以使用以下命令限制任何程序的执行时间:
You can limit execution time of any program using this command:
Ubuntu / Debian 的超时包可以在 Mac 上编译并且可以运行。
该软件包位于 http://packages.ubuntu.com/lucid/timeout
The Timeout Package from Ubuntu / Debian can be made to compile on Mac and it works.
The package is available at http://packages.ubuntu.com/lucid/timeout
您可以执行
ping -t 10 google.com >nul
>nul 删除输出。因此,它不会显示 64 BYTES FROM 123.45.67.8 BLAH BLAH BLAH,而是只显示空白换行符,直到超时。 -t 标志可以更改为任意数字。
You can do
ping -t 10 google.com >nul
the >nul gets rid of the output. So instead of showing 64 BYTES FROM 123.45.67.8 BLAH BLAH BLAH it'll just show a blank newline until it times out. -t flag can be changed to any number.