Ani Saghatelyan
Ani Saghatelyan

Reputation: 81

Scala external Process gets hanged

We need to run the following command as external process and process with input/output to insert data and get output.

docker-compose run --rm test-service

The source code sample is provided below:

// For process stuff
import scala.sys.process._

import java.io.File


import scala.sys.process._
import java.io._

object ProcessClient{

      def main(args: Array[String]) {

        val process = Process ("docker-compose  run --rm test-service",  new File("./"))
        val io = new ProcessIO (
           writer,
           out => {
             scala.io.Source.fromInputStream(out).getLines.foreach(println)
          },
           err => {
             scala.io.Source.fromInputStream(err).getLines.foreach(println)
            })
          process.run(io).exitValue()
      }

      def reader(input: java.io.InputStream) = {
        // read here
      }

      def writer(output: java.io.OutputStream) = {
        // write here
        //
      }
      // TODO: implement an error logger
    }

Result: The process gets hanged and no any status is provided.

enter image description here

Also tried with simple run approaches:

Process ("docker-compose  run --rm test-service",  new File("./"))!

Process ("docker-compose  run --rm test-service",  new File("./")).!

The content of docker-compose.yml file

version: '3.7'

services:
  test-service:
    container_name: cont1
    image: debian
    command:
     - bash
     - -c
     - |
        ls;

Upvotes: 1

Views: 49

Answers (0)

Related Questions