jatcwang jatcwang - 1 year ago 84
Bash Question

Subprocess.call or Subprocess.Popen cannot use executables that are in PATH (Linux/Windows)

I'm writing a programme that needs to run on both Linux and Windows and use executables (with parameters) that exist in the path. (Assumed)

Currently I'm having trouble running executables in windows using Subprocess.Call and Subprocess.Popen.

For a code like this, in windows 8

def makeBlastDB(inFile, inputType, dbType, title, outDir):
strProg = 'makeblastdb'
strInput = '-in ' + inFile
strInputType = '-input_type ' + inputType
strDBType = '-dbtype ' + dbType
strTitle = '-title ' + title
strOut = '-out ' + os.path.join(os.sep, outDir, title)
cmd = [strProg, strInput, strInputType, strDBType, strTitle, strOut]
result = Popen(cmd, shell=True)

I get the error message in console

'makeblastdb' is not recognized as an internal or external command,
operable program or batch file.

Even though I can run the same command using cmd.exe
I get the same response with shell=False.

Any ideas on how I can run the command assuming that the executable is in PATH environment variable? Thanks


Ok here is how I got it to work.

env = os.environ
proc = subprocess.Popen(args, env=env)