A safe way to start has the sbt task subprocess run with `sudo`

I use DevOps scripts with SBT script, and I need a task to run the subprocess through sudo, where the user can safely enter their password at the invitation sudo. Is there a way in sbt to allow the subprocess to temporarily still completely capture the console stdinby going through the password key presses up to sudo?

+4
source share
2 answers

Short answer

You can use the following code in build.sbtor Build.scala:

import sbt.Process

val sudo = taskKey[Unit]("Executes commands with sudo!")

sudo := {
  Process("sudo ls /", new File(".")).!<
}

"sudo ls /" , , "." , .

, , , , , , .

Sbt Process ProcessBuilder .

Scaladocs !<:

, , , , . . .

, . ProcessIO , .

Alternative

, String, File URL ProcessBuilder, Process. , :

sudo := "sudo ls /".!<

Java- .

+3

SBT, ( ) sudoers, .

Docker SBT.

. build.sbt:

docker := {
  (test in Test).value
  (stage in Docker).value
  "./docker-stuff.sh" !
}

... docker-stuff.sh sudo.

0

All Articles