unable to start a Process in Scala/Play application

我们两清 提交于 2019-12-13 02:48:50

问题


I have a ccm.py script which runs Cassandra cluster on local machine. I am able to run the command using windows command prompt. But I get error if I try to do so using Process class in Scala.

I want to run it before starting my test cases. So I am calling Process in beforeAll.

override def beforeAll():Unit = {
    println("starting cassandra cluster locally")
    val ccmCommand = Process("ccm.py start").!
  }

The error I get is

An exception or error caused a run to abort: Cannot run program "ccm.py": CreateProcess error=193, %1 is not a valid Win32 application 
java.io.IOException: Cannot run program "ccm.py": CreateProcess error=193, %1 is not a valid Win32 application
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

I also tried using cassandra -f command (which also works from cmd prompt) but I got error

An exception or error caused a run to abort: Cannot run program "cassandra": CreateProcess error=2, The system cannot find the file specified 
java.io.IOException: Cannot run program "cassandra": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

How can I solve the issue?

Update Thanks to Alex Ott, I have made some progress but I think there has to be a better and more reliable way to test the code and also make the code more portable

The code which seem to work so far is

override def beforeAll():Unit = {
    println("starting cassandra cluster locally")
      val ccmCommand = Process("python",Seq("C:\\Users\\manu\\Documents\\manu\\ccm-3.1.4.tar\\dist\\ccm-3.1.4\\ccm.py","start")).run //NOT GOOD. Using hardcoded path!!

    println(s"ccm returned ${ccmCommand}")
    Thread.sleep(30000) //the wait is too long and there is no guarantee that the cluster will be up properly
  }

Is there a better (w.r.t reliable without hard coding the path) to bring up the cluster before tests get executed.

来源:https://stackoverflow.com/questions/56142538/unable-to-start-a-process-in-scala-play-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!