2017-08-07 16 views

答えて

9

あなたはルールのrunブロック内shell()を複数回呼び出すことができます(規則はrun:ではなくshell:指定することができます):実行ブロックはPythonコードを受け入れるため、

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

そうでない場合は、あなたがのリストを構築することができ文字列などのコマンドおよびそれらを反復:

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

ルールの実行中にPythonコードを必要としない場合、あなたは内のトリプル引用符で囲まれた文字列を使用することができますブロックを実行し、シェルスクリプト内でコマンドを記述します。これは間違いなく、純粋なシェルルールの最も読みやすいです:

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

良い、感謝します。これらの例をWebサイトに表示することは、人々にとって有用なことです。 – tedtoal

関連する問題