0

One thing which sucks about Scala REPL is that there is no straight forward way of loading maven/sbt dependencies.

I found ammonite shell which has a convenient thing like load.ivy which is pretty sweet. it also has a decent wrapper over file system.

However I didn't find a way to do a sudo. So for example if I am looping over files in a directory and I don't have permission on a folder the command fails

ls.rec! cwd | (x => x.size -> x.last) sortBy (-_._1) take 3

Error

java.nio.file.AccessDeniedException: /Users/foo/Library/Saved Application State/com.bitrock.appinstaller.savedState
  sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
  sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
  sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
  sun.nio.fs.UnixFileSystemProvider.newDirectoryStream(UnixFileSystemProvider.java:407)
  java.nio.file.Files.newDirectoryStream(Files.java:457)

does anyone know how to do a sudo in the ammonite shell?

Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

1 Answers1

2

There are a number of ways to provide a password for sudo from JVM process calls:

Personally, what I found the most straight forward solution is to set the SUDO_ASKSPASS environment variable. Something like

val sudo = "sudo"
val askPass = "/usr/bin/ssh-askpass"
val procBuilder = Process(List(sudo, "-A", ???), None, "SUDO_ASKPASS" -> askPass)
val res = procBuilder.!
Community
  • 1
  • 1
0__
  • 66,707
  • 21
  • 171
  • 266