0

I have a batch file that's supposed to set PATH/PYTHON path variables and then invoke my python script (myscript.py), that's designed as an interactive console. I tried with the following:

@echo off
setlocal

if not defined PYTHONHOME (echo warning: PYTHONHOME environment variable is not defined. Using C:\Python24 by default.
SET PYTHONHOME=C:\Python24
if not exist "C:\Python24" ( echo warning: C:\Python24 does not exists. Please specify PYTHONHOME variable manually.))

color 1e
set PYTHONSTARTUP=%~dp0%myscript.py
set PYTHONPATH=%~dp0;%PYTHONPATH%
path %PYTHONHOME%;%PATH%
set PATHEXT=%PATHEXT%;.PY
cd %~dp0%
cmd.exe /k title Interactive Python Console 1.0
cls
%~dp0%myscript.py"

:done
endlocal

Before setting the colorpair (1e)for the console, I have appended directory containing myscript to path, python path and python24 is set as python home. My problem is: I am able to change the default font/background color of console, set the current window's title, but then neither cls (clearscreen) works, nor does my script is invoked. At the console, my pwd is script's directory. But when i enter 'python' at the prompt, myscript is invoked and I can see interactive console of my script. Anything missing from batch, that would automatically clear off the console after setting color/title, and invoke myscript.py?

2
  • Thank you for showing us the exact contents of your script. Could you double-check that that it is an accurate copy of the script? For instance, %~dp0%myscript.py" has only one double-quote character. set PYTHONPATH=%~dp0;%PYTHONPATH% has no % between %~dp0 and ;. Commented Dec 24, 2012 at 7:09
  • That was a typo.. leftover from formatting.. But thanks for pointing out Jim! Actually the problem appropriately pointed out by Bren (below) was the script starting a new console. Removing cmd /k solved the problem! Commented Dec 24, 2012 at 8:26

1 Answer 1

1

This doesn't really have anything to do with Python. cmd /k doesn't "set the window title", it starts a new command shell and leaves you in it, thus stopping your script midway through. Why don't you just do title My New Title? There's no need to use cmd.

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

Comments

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.