I try to write example code to combine akka and actor. But I got the error message when compile the code.
The code is really simple as showed below.
So, What have I got wrong?
[error] /home/qos/workspaces/actors/actors.scala:20: type mismatch;
[error]  found   : Unit
[error]  required: scala.sys.process.ProcessLogger
[error]         execute(cmd)
[error]                ^
[error] one error found
[error] (compile:compile) Compilation failed
The code is
import scala.sys.process._ 
import akka.actor._ 
object TryActor { 
  def main(args: Array[String]) { 
    val akkaSystem = ActorSystem("akkaSystem") 
    val worker = akkaSystem.actorOf(Props[Worker], name = "work0") 
    worker ! Command("ls") 
  } 
  case class Command(cmd: String) 
  class Worker extends Actor { 
    def receive = { 
      case Command(cmd) => { 
        println(cmd) 
        "echo recieve message from someone" ! 
        execute(cmd.toString) 
      } 
    } 
    def execute(cmd: String) { 
      val process = Process(cmd.toString) 
      process ! ProcessLogger(_ => {}) 
    } 
  } 
}
                It's interpreting execute(cmd.toString) as the argument to !, because newlines don't necessarily end statements. To fix this, don't use postfix syntax, which is deprecated for a reason:
def receive = { 
  case Command(cmd) => { 
    println(cmd) 
    "echo recieve message from someone".! 
    execute(cmd.toString) 
  } 
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With