Scala - System Command - problem with single quotes

141 views
Skip to first unread message

BHLB

unread,
Dec 19, 2012, 3:53:56 PM12/19/12
to scala...@googlegroups.com
Here is my problem: I want to execute an R script in batch mode from scala. Here is the code I try to use:

    import scala.sys.process._
    "R CMD BATCH --no-save --no-restore '--args a=1' /path/test.r".!

The command works when I cut and paste it in a terminal. But when I try it through scala, '--args is interpreted as the script file and I receive the Fatal error :

    Fatal error: cannot open file ''--args': No such file or directory

Everything works if I remove the argument block:

    import scala.sys.process._
    "R CMD BATCH --no-save --no-restore /path/test.r".!

Any guess on how to restore the expected "normal" execution?

Thanks in advance,

BHLB

Josh Suereth

unread,
Dec 19, 2012, 4:04:37 PM12/19/12
to BHLB, scala-user
Use these Seq() based API.

sys.process.Prcoess(Seq("R", "CMD", "BATCH", "--no-save", "--no-restore", "--args a=1", "/path/test/r").!

At least, IIRC, that's the syntax....

BHLB

unread,
Dec 19, 2012, 5:08:17 PM12/19/12
to scala...@googlegroups.com

Thanks a lot. It now works.

sys.process.Process(Seq("R", "CMD", "BATCH", "--no-save", "--no-restore", "--args a=1", "/path/test.r")).!
Reply all
Reply to author
Forward
0 new messages