は、あなたは常に、||
を条件付き「または」利用することができます:
rule some_rule:
output:
"outfile"
shell:
"""
command_that_errors || true
"""
# or...
rule some_rule:
output:
"outfile"
run:
shell("command_that_errors || true")
ゼロの通常終了コード(0)成功を意味し、何でも非ゼロを示し失敗。 || true
を含めると、コマンドがゼロ以外の終了コード(true
は常に0
を返す)で終了すると正常終了します。
特定のゼロ以外の終了コードを許可する必要がある場合は、シェルまたはPythonを使用してコードをチェックできます。 Pythonの場合、次のようなものになります。 shlex.split()
モジュールが使用されているため、シェルコマンドを引数の配列として渡す必要はありません。シェルスクリプトで
import shlex
rule some_rule:
output:
"outfile"
run:
try:
proc_output = subprocess.check_output(shlex.split("command_that_errors {output}"), shell=True)
# an exception is raised by check_output() for non-zero exit codes (usually returned to indicate failure)
except subprocess.CalledProcessError as exc:
if exc.returncode == 2: # 2 is an allowed exit code
# this exit code is OK
pass
else:
# for all others, re-raise the exception
raise
:
rule some_rule:
output:
"outfile"
run:
shell("command_that_errors {output} || rc=$?; if [[ $rc == 2 ]]; then exit 0; else exit $?; fi")