简体   繁体   English

如何在不使用Shell脚本的情况下获取timeout命令的输出

[英]How to get the output of timeout command without using a shell script

I am using a ssh command executor in java which runs the command and gets the output in stderr, stdout and an integer exit value. 我在Java中使用ssh命令执行程序,该命令执行程序运行命令并以stderr,stdout和整数退出值获取输出。 I am trying run a command with timeout like, 我正在尝试运行带有超时的命令,例如,

timeout 5s COMMAND

Is there a way to get a response in the stderr or the stdout so that I can know whether the command was timed out or not? 有没有办法在stderr或stdout中获得响应,以便我可以知道命令是否超时?

您可以使用应与ssh命令执行程序配合使用的shell脚本功能。

timeout 5s sleep 1s && (>&2 echo "Successful") || (>&2 echo "Timed out")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM