Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 578829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:18:07+00:00 2026-05-13T14:18:07+00:00

I have a batch file that tries to run the program specified in its

  • 0

I have a batch file that tries to run the program specified in its first line. Similar to Unix’s shebang:

C:\> more foo.bat
#!C:\Python27\python.exe
%PYTHON% foo-script.py
C:\>

What I want to know is: is there a way to automatically set %PYTHON% to C:\Python27\python.exe which is specified in the first line of the script following the shebang (#!)?

Background: I am trying to do this so as to explicitly specify the Python interpreter to invoke (as there are multiple Python interpreters installed on the system) in the wrapper script.

Assumption: You can assume that script already knows it’s own filename (foo) and %~dp0 is the directory of this script. How do we read the first line excluding the shebang?

Clarification: Adding C:\PythonXY to %PATH% is not a solution. The shebang line is supposed to be modified during install time (the original script is generated on the build machine only) on the user’s machine .. which may have multiple Python installations of the same version. And only the shebang line is modifyable (that is how the program works).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:18:07+00:00Added an answer on May 13, 2026 at 2:18 pm

    Firstly , on windows, there is no need for shebang. Its best to include the path of the Python interpreter to the PATH environment variable of the user who is running the script. That said, to get the first line in batch, you can use set

    set /p var=<file
    

    since you have multiple version of interpreter, why not just use the correct one when you invoke the script?

    c:\python27\bin\python.exe myscript.py
    

    Edit:

    @echo off
    set /p var=<test.py
    call %var:~2% test.py
    

    output

    C:\test>more test1.py
    #!c:\Python26\python.exe
    
    print "hello"
    
    
    C:\test>more test.bat
    @echo off
    set /p var=<test1.py
    call %var:~2% test1.py
    
    C:\test>test.bat
    hello
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Edit: answer to edited question: for string in "$(echo $result… May 16, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer I have a column of ones and zeros Maybe it… May 16, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer Annoyingly (however probably on purpose) the * in the assembly… May 16, 2026 at 6:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a batch file that runs a richcopy program, I am wanting to
I have a one line batch file that I want to call from a
I have two problems which are related. 1) I have a batch file that
I have a batch file that I have been using to install my C#
I have a windows batch file that does this: for %%s in (*.sql) do
I have a Perl/POE/Tk script running on Win32 ActivePerl that calls executables using system
I have an MSBuild task that executes (among other things) a call to xcopy.
I am trying to write a small batch file for a task I do
I'm trying to use 7-Zip to zip up a file via the system() function
I have created an installer for MyProgram using the Visual Studio Installer (Visual Studio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.