如何从scala REPL执行unix命令“top”?

时间:2014-01-09 06:45:07

标签: scala unix

从scala REPL中,大多数unix命令都能正常工作。以下是我刚才尝试过的几个:

  1. “ps -ef”#| “grep java”!
  2. “df -k”!
  3. “ls -al ..”!
  4. 但是,当我尝试“顶部”时,我得到以下内容:

    scala> "top" !
    warning: there were 1 feature warning(s); re-run with -feature for details
    error: initializing curses
    res13: Int = 1
    

    请让我知道我错过了什么。

1 个答案:

答案 0 :(得分:1)

当您分叉进程时,它没有连接到tty。

尝试批处理模式,top -b -n 1

替代语法:

scala> Process("top -b -n 1").run

比较Linux上的错误:

scala> import sys.process._
import sys.process._

scala> "top".!
    top: failed tty get

在OS X上,他们称之为“记录模式”:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/top.1.html

我猜:

scala> "top -l 1".!