2017-08-07 139 views

回答

9

您可以在规则的run块内调用shell()多次(规则可以指定run:而非shell:):

rule processing_step: 
    input: 
     # [...] 
    output: 
     # [...] 
    run: 
     shell("somecommand {input} > tempfile") 
     shell("othercommand tempfile {output}") 

否则,由于运行块接受Python代码,你可以建立一个列表命令字符串和遍历他们:

rule processing_step: 
    input: 
     # [...] 
    output: 
     # [...] 
    run: 
     commands = [ 
      "somecommand {input} > tempfile", 
      "othercommand tempfile {output}" 
     ] 
     for c in commands: 
      shell(c) 

如果没有规则的执行过程中需要Python代码,你可以在中使用三引号字符串块,然后像在shell脚本中那样编写命令。这可以说是最可读纯壳规则:

rule processing_step: 
    input: 
     # [...] 
    output: 
     # [...] 
    shell: 
     """ 
     somecommand {input} > tempfile 
     othercommand tempfile {output} 
     """ 

如果壳命令取决于成功/前面的命令的故障时,它们可以与通常的外壳脚本运营商如||&&接合:

rule processing_step: 
    input: 
     # [...] 
    output: 
     # [...] 
    shell: 
     "command_one && echo 'command_one worked' || echo 'command_one failed'" 
+1

好,谢谢。人们在网站上展示这些例子会很有用。 – tedtoal