a shell command is not writing in a file in python code

172 Views Asked by At

While using the TreeTagger the following problem occured

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

The snippet above works in the command line. But when I try to execute it in a python code, nothing is written in the output file even though any error is given.

1

There are 1 best solutions below

0
On

This is the way I used cmd to include a command line within a programme I wrote a while ago in python 2.7. Obviously you will have to change for your type of data.

`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)`

In this link you can get some other examples. [https://www.cyberciti.biz/faq/python-run-external-command-and-get-output/][1]

Hope this is useful.