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>
相关问答