sách gpt4 ai đã đi

shell - Cách được khuyến nghị để thực thi nhiều lệnh shell bằng shell()

In lại 作者:行者123 更新时间:2023-12-04 01:33:17 30 4
mua khóa gpt4 Nike

在snakemake中,使用shell()函数执行多个命令的推荐方式是什么?

1 Câu trả lời

您可以调用shell()多次内chạy规则块(规则可以指定 run: Còn hơn là shell: ):

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

否则,由于 run 块接受 Python 代码,您可以将命令列表构建为字符串并遍历它们:

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

如果在执行规则期间不需要 Python 代码,则可以在 shell 中使用三引号字符串。块,然后像在 shell 脚本中一样编写命令。对于纯 shell 规则来说,这可以说是最易读的:

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

如果 shell 命令依赖于前面命令的成功/失败,它们可以与通常的 shell 脚本操作符一起使用,如 ||&& :

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

关于shell - 使用 shell() 执行多个 shell 命令的推荐方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45553762/

30 4 0
Bài viết được đề xuất: javascript - Dropzone 上传进度
Bài viết được đề xuất: spring - 如何在 Spring Data REST 项目中使用 DTO?
Bài viết được đề xuất: tensorflow - 为什么 tensorflow 只是输出被杀死
Bài viết được đề xuất: 使用 rename_all 从列名中删除后缀?
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com