简体   繁体   English

如何通过 python 调用/运行软件?

[英]How can I call/run a software by python?

I'm trying to make a simple script to run different tasks one by one (one after another) but I don't know how can I run the program by python script.我正在尝试制作一个简单的脚本来逐个(一个接一个)运行不同的任务,但我不知道如何通过 python 脚本运行程序。 I know that it should be simple: but I couldn't find it any where.我知道它应该很简单:但我在任何地方都找不到它。 my example is this:我的例子是这样的:

samtools merge filename.bam file1.sorted.bam file2.sorted.bam file3.sorted.bam file4.sorted.bam

samtools index filename.bam 
samtools idxstats filename.bam > filename.txt 
samtools pileup -vcf path/filename.fa filename_sorted.bam

I want the python to run the first command and after its finished then goes to the next one!我希望 python 运行第一个命令,完成后转到下一个命令! it's important that it wait's until it's finished!重要的是要等到完成!

from subprocess import call # call runs an external program and waits for it to quit

for command in ("samtools merge filename.bam file1.sorted.bam file2.sorted.bam file3.sorted.bam file4.sorted.bam", 
                "samtools index filename.bam", 
                "samtools idxstats filename.bam > filename.txt", 
                "samtools pileup -vcf path/filename.fa filename_sorted.bam"):
    # shell=True is so you can handle redirects like in the 3rd command
    call(command, shell=True) 

Use the subprocess module .使用子流程模块 There are lots of examples at the bottom of the page.页面底部有很多示例。

暂无
暂无

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

相关问题 如何在使用swift的同时运行/调用python脚本? - How can I run/call a python script while using swift? 如何使用 python 下载 Minecraft 服务器软件? - How can I use python to download Minecraft server software? 如何强制从python运行jar并与SDK 1.7一起运行? - How can I call run a jar from python while obligating it to run with SDK 1.7? 如何在另一个python脚本的循环内调用和运行python mainmodel.py? - How I can call and run the python mainmodel.py inside a loop in another python script? 当我运行一个调用另一个 python 文件时,如何将一些 arguments 传递给它? - when I run a python file which call another one ,how can I pass some arguments to it? python selenium如何在没有浏览器自动化测试软件版本的情况下运行在您的浏览器上? - How can python selenium run on your browser without the automated test software version of the browser? 如何在我的Swift软件应用程序中为我的函数计算运行Python代码? - How do I run Python code for my function calculations in my Swift software App? 我如何在某个时间戳记时间运行python函数。 没有外部软件? - How do i run a python function at a certain timestamp time. Without outside software? 制作可以由其他软件运行的独立python脚本 - Making a standalone python script that can be run by another software 如何使用CMake链接同一软件的Python 2和Python 3库 - How I can use CMake for linking Python 2 and Python 3 libraries for a same software
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM