linux - 在 Scala 中执行需要用户交互的 OS 命令

标签 linux scala unix process user-interaction

如何使用 Scala 进程执行需要用户交互的操作系统命令?

为了说明这一点,考虑例如 Unix/Linux 操作系统中的 passwd,如下所示,

import sys.process._
import scala.language.postfixOps

等等

scala> "passwd"!

(current) UNIX password: passwd: Authentication token manipulation error
passwd: password unchanged
Changing password for userabc
res0: Int = 10

最佳答案

使用“!<”代替“!”

"passwd"!<

来自scala.sys.process.ProcessBuilder特点:

/** Starts the process represented by this builder, blocks until it exits, and
  * returns the exit code.  Standard output and error are sent to the console.
  */
def ! : Int

/** Starts the process represented by this builder, blocks until it exits, and
  * returns the exit code.  Standard output and error are sent to the console.
  * The newly started process reads from standard input of the current process.
  */
def !< : Int

关于linux - 在 Scala 中执行需要用户交互的 OS 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26183943/

相关文章:

linux - 如何在 ssh 命令中使用长输入参数正确转义 qsub 命令?

c - 使用 libblkid 时出错

scala - 重试返回 Future 的函数

scala - 隐式使用Scala进行类型相等

linux - find -exec 无法识别参数

ruby-on-rails - rails Assets :precompile Yarn executable was not detected in the system

php - 在 Linux 中终止 php 浏览器请求

scala - <> 运算符在 Slick 中起什么作用?

c - Longjmp 超出信号处理程序?

linux - 尝试将正则表达式传递给 grep