Python os.system () in Eclipse

I use Python to call the program:

print cmd
os.system(cmd)

Below is the output of a command printthat shows cmdcalls sclitewith several parameters, and then redirects the output to dump.

C:/travel/sctk-2.4.0/bin/sclite -r C:/travel/tempRef.txt -h C:/travel/tempTrans.txt -i spu_id > C:/travel/dump

When I run the command in cygwin, it dumpcontains the desired output. When I open Python in cygwin and use os.system(cmd)there, it dumpcontains the desired result. If I run my Python script from cygwin, it dumpcontains the desired result. When I run my Python script in Eclipse dumpit contains nothing, i.e. A file is created, but nothing is written to it.

I tried the same subprocess(cmd,shell=True)with the same results: running the script in Eclipse results in an empty file, while the rest work fine. I assume that something is wrong with Eclipse / Pydev, but I'm not sure what.

+3
source share
1 answer

One way to solve this problem might be to use Popen -

from subprocess import Popen
cmd="C:/travel/sctk-2.4.0/bin/sclite -r C:/travel/tempRef.txt -h C:/travel/tempTrans.txt -i spu_id"
f=open('C:/travel/dump','w')
p=Popen(cmd.split(),stdout=f)

But that still doesn't explain your weird behavior in Eclipse ...

0
source

All Articles