シェルスクリプトを使用せずにタイムアウトコマンドの出力を取得する方法

シェルスクリプトを使用せずにタイムアウトコマンドの出力を取得する方法

私はコマンドを実行し、stderr、stdout、および整数終了値で出力を取得するJavaでsshコマンドランチャーを使用しています。次のタイムアウトのあるコマンドを実行しようとしています。

    timeout 5s COMMAND

コマンドがタイムアウトしたかどうかを知るためにstderrまたはstdoutから応答を取得する方法はありますか?

ベストアンサー1

からman timeout

   If  the  command times out, and --preserve-status is not set, then exit
   with status 124.  Otherwise, exit with the status of  COMMAND.   If  no
   signal  is specified, send the TERM signal upon timeout.  The TERM sig‐
   nal kills any process that does not block or catch that signal.  It may
   be  necessary  to  use the KILL (9) signal, since this signal cannot be
   caught, in which case the exit status is 128+9 rather than 124.

だから... timeout 5s command || [ $? -eq 124 ] && echo timeouted

おすすめ記事