-1

I want to call my python script runner.py from Scala program, I doing it like this:

runner.py:

print("testing")

`program.scala:

val res = "python3 runner.py" !

The problem is that this only return 0, but not the printed output. How can I get that in Scala?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
  • To run external programs, you can use methods from the package scala.sys.process https://www.scala-lang.org/api/current/scala/sys/process/index.html – KosWarm Apr 19 '21 at 15:55
  • 1
    Does this contain enough material to either answer your question, or at least formulate more precisely what the problem is? https://stackoverflow.com/questions/15411728/scala-process-capture-standard-out-and-exit-code In particular, [this here](https://stackoverflow.com/a/15438493/2707792) shows how to capture everything. – Andrey Tyukin Apr 19 '21 at 16:17

1 Answers1

1

As explained in the ScalaDocs, ! returns the process exit code. !! returns the process StdOut. If you need both you'll want to add a ProcessLogger.

jwvh
  • 50,871
  • 7
  • 38
  • 64