简体   繁体   English

使用多行输入Scala处理包

[英]Using multi-line inputs Scala process package

I have the following code: 我有以下代码:

s"""java ${MemString} -jar ${toolsFolder}/GenomeAnalysisTK.jar -T IndelRealigner -R ${refFolder}/${RefFileName} -I ${tmpFolder}/region${chrRegion}.bam
    -targetIntervals ${tmpFolder}/region${chrRegion}.intervals -o ${tmpFolder}/region${chrRegion}-2.bam -L ${tmpFolder}/bed${chrRegion}.bed""" !
s"rm -rf ${tmpFolder}/region${chrRegion}.bam, ${tmpFolder}/region${chrRegion}.bai, ${tmpFolder}/region${chrRegion}.intervals" !

Since I have a big input string for the first line I am trying to use multi-line string input for the process. 由于第一行有很大的输入字符串,因此我试图在过程中使用多行字符串输入。 But I am getting the following error: 但是我收到以下错误:

sbt package
[info] Set current project to DNASeqAnalyzer (in build file:/home/sarthaksharma/Lab3/dnaseq_analyzer/)
[info] Compiling 1 Scala source to /home/sarthaksharma/Lab3/dnaseq_analyzer/target/scala-2.11/classes...
[error]    /home/sarthaksharma/Lab3/dnaseq_analyzer/src/main/scala/DNASeqAnalyzer.scala:148    : type mismatch;
[error]  found   : String
[error]  required: scala.sys.process.ProcessLogger
[error]             s"rm -rf ${tmpFolder}/region${chrRegion}.bam, ${tmpFolder}/region${chrRegion}.bai, ${tmpFolder}/region${chrRegion}.intervals" !
[error]             ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed

It is running fine if I comment the first line of the code. 如果我注释代码的第一行,它运行良好。 Why is it showing error for a different line? 为什么在另一行显示错误? How can I run this? 我该如何运行?

The problem occurs because you hit the alternative method .!(logger) , instead of the one without arguments. 发生此问题的原因是您点击了替代方法.!(logger)而不是没有参数的方法。 So try just to write the dot explicitly: 因此,尝试仅明确地写点:

s"""long 
command""".!
s"another command".!

Also, I would recommend you to construct any commands as sequences of strings, this solves your long command problem and is less ambiguous regarding how arguments will be interpreted (and escaped): 另外,我建议您将任何命令构造为字符串序列,这可以解决您的长命令问题,并且在如何解释(和转义)参数方面也不太含糊:

Seq(
  "command",
  s"option=${value}",
  "argument"
).!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM