我注意到,Scala 并不总是按顺序执行指令。例如,如果您有以下说明。
var a = command1.!
var b = command2.!
第二条指令可能会在第一条指令之前执行,因为它与该指令没有任何依赖性。所以,我的问题是,如何强制在第一条指令之后执行第二条指令。
最佳答案
回答问题“我如何编写 ProcessBuilder?”,文档说:
Two existing ProcessBuilder can be combined in the following ways:
They can be executed in parallel, with the output of the first being fed as input to the second, like Unix pipes. This is achieved with the #| method.
They can be executed in sequence, with the second starting as soon as the first ends. This is done by the ### method.
The execution of the second one can be conditioned by the return code (exit status) of the first, either only when it's zero, or only when it's not zero. The methods #&& and #|| accomplish these tasks.
关于java - 如何强制 Scala 中指令的执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30829572/