Skip to content

Instantly share code, notes, and snippets.

@astail
Created December 27, 2018 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astail/ed21e3027c0e046f917413634fea4030 to your computer and use it in GitHub Desktop.
Save astail/ed21e3027c0e046f917413634fea4030 to your computer and use it in GitHub Desktop.
import sys.process._
object search {
def main: Option[String] = {
retry2(iphone)
}
def iphone: Option[String] = {
val ping = try {
Process("ping -c 5 192.168.0.20") #&& ("echo okkk") !!
} catch {
case e: Throwable => "error"
}
if (ping == "okkk") Some("家にいます") else None
}
def retry2[R](f: => R, n: Int = 40): R = {
if (n > 0) {
f match {
case Some(s) => f
case None => retry2(f, n - 1)
}
} else f
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment