扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

scala鎬庝箞璋冪敤shell鑴氭湰

扬州沐宇科技
2024-01-11 23:08:11
scala, shell

鍦⊿cala涓皟鐢╯hell鑴氭湰鍙互浣跨敤Process瀵硅薄鏉ユ墽琛宻hell鍛戒护銆?/p>

浠ヤ笅鏄竴涓ず渚嬶細

import sys.process._

object ShellCommand {
  def main(args: Array[String]): Unit = {
    val command = "sh /path/to/script.sh" // 鏇挎崲鎴愪綘鐨剆hell鑴氭湰璺緞鍜屾枃浠跺悕

    val exitCode = command.!
    if (exitCode == 0) {
      println("Shell command executed successfully.")
    } else {
      println(s"Shell command failed with exit code $exitCode.")
    }
  }
}

鍦ㄤ笂闈㈢殑绀轰緥涓紝鎴戜滑浣跨敤!鎿嶄綔绗︽潵鎵цshell鍛戒护锛屽苟閫氳繃杩斿洖鐨勯€€鍑虹爜鏉ュ垽鏂懡浠ゆ槸鍚︽墽琛屾垚鍔熴€傚鏋滈€€鍑虹爜涓?锛屽垯琛ㄧず鍛戒护鎵ц鎴愬姛銆?/p>

扫码添加客服微信