下面的find
shell命令会返回我系统上的预期结果:
➜ ~ find /Users/ihainan/IdeaProjects/ScalaForTheImpatient -name "*.class"
/Users/ihainan/IdeaProjects/ScalaForTheImpatient/src/main/scala/character_8/character_8/Person.class
/Users/ihainan/IdeaProjects/ScalaForTheImpatient/src/main/scala/character_8/character_8/SecretAgent.class
但是当我执行以下scala源代码时,它会在同一台机器上返回空结果:
object Ex9 {
def main(args: Array[String]): Unit = {
import sys.process._
val classFiles = s"""find /Users/ihainan/IdeaProjects/ScalaForTheImpatient -name "*.class" """ !!
println(classFiles)
}
}
Scala版本:2.11.5,系统:macOS Sierra,JRE版本:1.8.0_91
有任何想法或建议吗?
答案 0 :(得分:1)
使用postfix !!
简单命令[{1}}将起作用
echo ""
对于scala> "echo prayagupd" !!
res6: String =
"prayagupd
"
,你也可以实现它(删除多行字符串find
到字符串""" """
),
""
但使用scala> "find /Users/ihainan/IdeaProjects/ScalaForTheImpatient -name *.class"!!
例如
Seq("bash", "-c", "your command")
相当于运行以下bash命令,
scala> import sys.process._
import sys.process._
scala> Seq("bash", "-c", "find /Users/ihainan/IdeaProjects/ScalaForTheImpatient -name *.class")!!