shell命令没有写入python cod中的文件

2024-04-19 04:55:48 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用TreeTagger时,出现了以下问题

import os
os.system("bin/tree-tagger lib/english-utf8.par inputfile outputfile")

上面的代码段在命令行中工作。但是,当我尝试在python代码中执行它时,即使给出了任何错误,也不会在输出文件中写入任何内容。你知道吗


Tags: 命令行importtreebinenglishoslib代码段
1条回答
网友
1楼 · 发布于 2024-04-19 04:55:48

这就是我使用cmd将命令行包含在我不久前用python2.7编写的程序中的方式。显然,您必须更改您的数据类型。你知道吗

`import sys, os, subprocess
def velvet_assembly(fastqs,output):

    #cmd is a command line within the programme#
    cmd=['velveth', output, '59', '-fastq.gz', '-shortPaired',fastqs[0],fastqs[1]]
    my_file=subprocess.Popen(cmd)
    my_file.wait()
velvet_assembly(fastqs,output)`

在这个链接中你可以得到一些其他的例子。 [https://www.cyberciti.biz/faq/python-run-external-command-and-get-output/][1]

希望这是有用的。你知道吗

相关问题 更多 >