我正在尝试在后台运行scala控制台中的守护进程。我可以让它运行该程序,但它在运行时锁定控制台窗口,因此迫使我使用单独的窗口来停止守护程序以解锁原始控制台。我通过sbt在Windows PowerShell中运行scala控制台。
我可以使用命令提示符在后台使用start /b program
成功运行程序,但在scala控制台中运行("start /b program").!
失败。
这将在scala控制台中运行程序,但会锁定窗口:
("cmd /c start program").!
如何让程序在后台成功运行,这样我仍然可以访问当前的控制台?
我一直在使用/E:ON
使用/b
作为start
的扩展,但无济于事。
这些是来自cmd /?
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>cmd /?
Starts a new instance of the Windows XP command interpreter
CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
[[/S] [/C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
/D Disable execution of AutoRun commands from registry (see below)
/A Causes the output of internal commands to a pipe or file to be ANSI
/U Causes the output of internal commands to a pipe or file to be
Unicode
/T:fg Sets the foreground/background colors (see COLOR /? for more info)
/E:ON Enable command extensions (see below)
/E:OFF Disable command extensions (see below)
/F:ON Enable file and directory name completion characters (see below)
/F:OFF Disable file and directory name completion characters (see below)
/V:ON Enable delayed environment variable expansion using ! as the
delimiter. For example, /V:ON would allow !var! to expand the
variable var at execution time. The var syntax expands variables
at input time, which is quite a different thing when inside of a FOR
loop.
/V:OFF Disable delayed environment expansion.
答案 0 :(得分:1)
你应该在SBT中使用forking,这正是它的用途。
根据您的情况,在SBT版本中设置此设置:
fork in run := true
默认情况下,stdin不会连接到分叉进程,启用它:
connectInput in run := true
答案 1 :(得分:0)
感谢@ som-snytt链接@ michael.kebe关于此SO条目的答案:How does the “scala.sys.process” from Scala 2.9 work?
val pb = Process("""program""").run
完全符合我的要求