Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Java's redirectInput rather than sys.process's connectInput #3970

Merged
merged 1 commit into from
Feb 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions run/src/main/scala/sbt/Fork.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
package sbt

import java.io.File
import java.lang.ProcessBuilder.Redirect

import scala.sys.process.Process
import OutputStrategy._
import sbt.internal.util.Util

import java.lang.{ ProcessBuilder => JProcessBuilder }

/**
* Represents a command that can be forked.
*
Expand Down Expand Up @@ -45,13 +49,19 @@ final class Fork(val commandName: String, val runnerClass: Option[String]) {
(classpathEnv map { value =>
Fork.ClasspathEnvKey -> value
})
val process = Process(command, workingDirectory, environment.toList: _*)
val jpb = new JProcessBuilder(command.toArray: _*)
workingDirectory foreach (jpb directory _)
environment foreach { case (k, v) => jpb.environment.put(k, v) }
if (connectInput)
jpb.redirectInput(Redirect.INHERIT)
val process = Process(jpb)

outputStrategy.getOrElse(StdoutOutput) match {
case StdoutOutput => process.run(connectInput)
case out: BufferedOutput => out.logger.buffer { process.run(out.logger, connectInput) }
case out: LoggedOutput => process.run(out.logger, connectInput)
case out: CustomOutput => (process #> out.output).run(connectInput)
case StdoutOutput => process.run(connectInput = false)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should note that my testing in the context of the Scala build was through this code path (outputStrategy = StdoutOutput). I think the way the output is redirected should not have a bearing on how connectInput works, but if you can think of any other use cases to test for, I'd suggest doing some manual testing of this before the release.

case out: BufferedOutput =>
out.logger.buffer { process.run(out.logger, connectInput = false) }
case out: LoggedOutput => process.run(out.logger, connectInput = false)
case out: CustomOutput => (process #> out.output).run(connectInput = false)
}
}
private[this] def makeOptions(jvmOptions: Seq[String],
Expand Down