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 678409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:08:47+00:00 2026-05-14T01:08:47+00:00

Sometimes (in customer’s PCs) I need a python script to execute in the Windows

  • 0

Sometimes (in customer’s PCs) I need a python script to execute in the Windows shell like a .CMD or .BAT, but without having the .py or .pyw extensions associated with PYTHON / PYTHONW.

I came out with a pair of ‘quick’n dirty’ solutions:

1)

"""
e:\devtool\python\python.exe %0 :: or %PYTHONPATH%\python.exe
goto eof:
""" 
# Python test
print "[works, but shows shell errors]"

2)

@echo off
for /f "skip=4 delims=xxx" %%l in (%0) do @echo %%l | e:\devtools\python\python.exe
goto :eof
::----------

# Python test
print "[works better, but is somewhat messy]"

Do you know a better solution? (ie: more concise or elegant)


Update:

based on @van answer, the more concise way I found (without setting ERRORLEVEL)

@e:\devtools\python\python.exe -x "%~f0" %* & exit /b

### Python begins....
import sys

for arg in sys.argv:
    print arg

raw_input("It works!!!\n")

###
  • 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-14T01:08:48+00:00Added an answer on May 14, 2026 at 1:08 am

    You can try to create a script what is both python and windows shell script. In this case you can name you file my_flexible_script.bat and execute it either directly or via python ....

    See a content of pylint.bat file from pylint:

    @echo off
    rem = """-*-Python-*- script
    rem -------------------- DOS section --------------------
    rem You could set PYTHONPATH or TK environment variables here
    python -x "%~f0" %*
    goto exit
    
    """
    # -------------------- Python section --------------------
    import sys
    from pylint import lint
    lint.Run(sys.argv[1:])
    
    
    DosExitLabel = """
    :exit
    exit(ERRORLEVEL)
    rem """
    

    It is similar to what you do, but has more compliant dual-script support.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes we deploy applications behind customer firewall and we need read only access to
I have tables like Customer , Purchase etc which sometimes have associated documents with
Sometimes we receive stack traces from our customer with wrong line numbers. It happens
Sometimes I need to quickly extract some arbitrary data from XML files to put
Sometimes my Oracle database on Windows gets hosed. How do I do a manual
I'm sure most people who use the entity framework sometimes need an entity only
I have a windows service that is, intermittently, throwing an exception that sometimes kills
Sometimes, a customer (or tester) needs a patch on an installation of the product
I have a struct more or less like this: [Serializable] [XmlRoot(Customer)] public struct TCustomer
Sometimes we use shortcuts to denote something. For e.g we can write Customer Reference

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.