3

I'm exploring to use Scala REPL bridge to shell.It is mainly achieved by import sys.process._ package and I can use "ls" ! to execute shell.
Now, I want to use "vi" ! to open a interactive vi editor, it is really crazy but very exciting. After entering the cmd in REPL, the terminal opens a init vi canvas. Unfortunately, the terminal is not reading any input from my keyboard.

Is it possible to open a vi in REPL?

rkta
  • 3,959
  • 7
  • 25
  • 37
LoranceChen
  • 2,453
  • 2
  • 22
  • 48
  • I don't think the standard REPL can do that, but it should be easy in [ammonite](http://ammonite.io/). – jwvh Jul 04 '17 at 05:28
  • @jwvh, its really amazing even in `ssh`. It's my desired: `%("bash", "-c", """sshpass -p '123456' ssh lorance@192.168.1.230 -t vi""") `. Work well in amm!!! – LoranceChen Jul 04 '17 at 09:01
  • 1
    This can probably be simplified to `%sshpass("-p", "123456", "ssh", "lorance@192.168.1.230", "-t" "vi")` And of course, `%vim "foo.txt"` should work too. Or `%python` to open up a Python REPL, `%sbt`, etc. – Li Haoyi Jul 05 '17 at 17:09

1 Answers1

1

from https://stackoverflow.com/a/29972867/1573825 (java solution):

import java.lang.{Process, ProcessBuilder}

 System.out.println("STARTING VI");
 val processBuilder = new ProcessBuilder("/usr/bin/vi")
 processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT)
 processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT)
 processBuilder.redirectInput(ProcessBuilder.Redirect.INHERIT)

 val p = processBuilder.start()
  // wait for termination.
  p.waitFor()
System.out.println("Exiting VI")

it doesn't even corrupt readline.

vitalii
  • 3,335
  • 14
  • 18