0

I have Python installed in:

C:\Python27\python.exe

I need to run Python script from batch file by setting environment variable that points to Python exe. Update: based on response here, i found that install directory in registry has:

HKLM\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath

with Name:Default and data: C:\Python27\

Now, runing the batch command like this:

for /f "tokens=*" %%A in ('REG QUERY "HKLM\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath" /v Default') DO (
    set CHESSPYTHONPATHv1=%%B)

Gives error:

The System was unable to find specified registry key or value.

Q1) what am i doing wrong?
Q2) This still requires version number to be known by manually looking into registry . if batch file was to run on another PC, with different Python version, this would fail. How do i specify the registry search path which determines version installed too?
Thanks
sedy

1
  • 1
    Check out package "os"; the path attribute for packages is a huge help. Commented Oct 20, 2015 at 0:03

1 Answer 1

1

I'm assuming that you need to do everything in batch. You can try the following:

@echo off
for /f "delims=" %%a in ('REG QUERY "HKLM\SOFTWARE\Python\PythonCore" /s ^| findstr InstallPath') do  (
  set key=%%a
  goto :endfor
)
:endfor
for /f "tokens=2*" %%a in ('REG QUERY %key% /ve') do set "CHESSPYTHONPATHv1=%%~bpython.exe"
echo %CHESSPYTHONPATHv1%

The first result in the first registry query should contain the InstallPath. The second query retrieves the Python path.

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

1 Comment

Thanks ..works like a charm(just had to change little bit for 64 bit Win)

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.