0

consider portion of Python code(Python 2.7) on Win 7 machine,

toolPath="C:\\Program Files (x86)\\Target Compiler Technologies\\adsp2-12R2\\bin\\WINbin"

This is executed from python script under

C:\dev\bin\toplevel\python

Now, I need to execute a command that runs(compiles and builds a DSP library, .prx is a project file for the library) as

C:\Program Files (x86)\Target Compiler Technologies\adsp2-12R2\bin\WINbin\chessmk.exe ".\..\..\..\dev\lib\adsp2\mylibs.prx -r -s

I am able to do that in cmd.exe shell as

%toolPath%\chessmk.exe "..\..\..\dev\lib\adsp2\mylibs.prx" -r -s

I can do the same in Python as

cmd = '"C:\\Program Files (x86)\\Target Compiler Technologies\\adsp2-12R2\\bin\\WINbin\\chessmk.exe" "C:\\SVN\\ASROmni\\trunk1\\\dev\\lib\\adsp2\\mylibs.prx" -r'
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=False)

But, I have not been able to write similar code for Python, with relative paths and using toolpath variable. for example,

cmd = 'toolPath+"\\chessmk.exe" ".\\..\\..\\..\\dev\\lib\\adsp2\\mylibs.prx" -r -s'
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=False)

gives error:

WindowsError: [Error 2] The system cannot find the file specified

following did not work too:

cmd = '"C:\\Program Files (x86)\\Target Compiler Technologies\\adsp2-12R2\\bin\\WINbin\\chessmk.exe" ".\\..\\..\\..\\dev\\lib\\adsp2\\mylibs.prx" -r'
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=False)

Update: from one of the comments, I tried

cmd = os.path.join(toolPath,"chessmk.exe")+' C:\\SVN\\ASROmni\\trunk1\\\dev\\lib\\adsp2\\mylibs.prx -r'

it works,but the relative path one

cmd = os.path.join(toolPath,"chessmk.exe")+' .\\..\\..\\..\\dev\\lib\\adsp2\\mylibs.prx -r'

still dosn't.

any help.( This is my first day with python, so bear with me)
please note that the cmd should be run from within Python, not invoking shell=True.
Thanks
sedy

1 Answer 1

1

It may be how you're passing the arguments to check_output(), try this instead:

toolPath = ('"C:\\Program Files (x86)\\Target Compiler Technologies\\'
            'adsp2-12R2\\bin\\WINbin\\chessmk.exe"')

cmd = [toolPath, '"..\..\..\dev\lib\adsp2\mylibs.prx"', '-r' '-s']

subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)

However the relative path for the location of mylibs.prx may still be a problem. You might be able to make it work by calling os.chdir() right before calling check_output().

Sign up to request clarification or add additional context in comments.

6 Comments

Hi Martineau, well %toolpath% was used as I could only create environment variables in shell. here,In python, toolpath is an ordinary variable, so, does it still need os.environ?
Using a relative path is making assumption about the current working directory. You can either change the cwd appropriately using os.chdir() before calling check_output() or pass the argument with an absolute path.
Hi martineau, my bad, I was using extra // for relative path, so that is why it did not work. Now, It works. Thanks. One small query though, can i direct op of execution to STDOUT if not an error?
That good to hear. You don't need to do anything for it to go to stdout (that's the default).
I checked and the subprocess.check output only directs child process stdout to stderror, but when not in error, i should be able to see the message from child process(here, the DSP library that is executed)on sucess too, which i don't see .
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.