How does the “scala.sys.process” from Scala 2.9 work?

前端 未结 7 1106
甜味超标
甜味超标 2020-11-30 18:09

I just had a look at the new scala.sys and scala.sys.process packages to see if there is something helpful here. However, I am at a complete loss.<

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 18:44

    If I understand the dialog so far, one aspect of the original question is not yet answered:

    1. how to "detach" a spawned process so it continues to run independently of the parent scala script

    The primary difficulty is that all of the classes involved in spawning a process must run on the JVM, and they are unavoidably terminated when the JVM exits. However, a workaround is to indirectly achieve the goal by leveraging the shell to do the "detach" on your behalf. The following scala script, which launches the gvim editor, appears to work as desired:

    val cmd = List(
       "scala",
       "-e",
       """import scala.sys.process._ ; "gvim".run ; System.exit(0);"""
    )
    val proc = cmd.run
    

    It assumes that scala is in the PATH, and it does (unavoidably) leave a JVM parent process running as well.

提交回复
热议问题