【问题标题】:how to handle user interaction of external commands in scala如何在scala中处理外部命令的用户交互
【发布时间】:2018-07-08 13:18:11
【问题描述】:

我有一个删除数据的删除脚本,这样做时会提示要求继续。我想在 cucumber-cli 中传递我的命令和用户交互“Y”

sys.process.Process("abc delete #>> Y", new java.io.File(getProjectPath)).!

我试过了

  • echo Y | abc delete
  • abc delete <<< Y
  • printf Y | abc delete

但似乎没有一个在 scala-cucumber 中起作用。它仅适用于终端。 可能是什么问题?

那是我的O/p

  Press 'Y' to continue...
Exception in thread "main" java.io.EOFException: Console has reached end of input
    at scala.io.StdIn$class.readChar(StdIn.scala:93)
    at scala.io.StdIn$.readChar(StdIn.scala:229)

【问题讨论】:

    标签: scala testing cucumber command-line-interface integration


    【解决方案1】:

    我不知道 cucumber-cli 是什么,但这可能会对你有所帮助:

    import java.io.ByteArrayInputStream
    
    val inputString = "y"
    val is = new ByteArrayInputStream(inputString.getBytes("UTF-8"))
    val process = Process("abc delete") #< is
    process.run()
    

    【讨论】:

      【解决方案2】:

      ("echo Y" #> edhCommand).!工作过

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多