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

  • Home
  • SEARCH
  • 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 7830351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:11:55+00:00 2026-06-02T11:11:55+00:00

I know my title is not descriptive so let me try to explain it

  • 0

I know my title is not descriptive so let me try to explain it here.

Normally I execute my python script like this:

D:\github\Miscellaneous-Programs\Python>python check.py -h
hello
['check.py', '-h']

Now what I did is added the folder D:\github\Miscellaneous-Programs\Python in my windows path environment variable. Than I tried to execute my script like this:

C:\Users\noob>check -h
hello
['D:\\github\\Miscellaneous-Programs\\Python\\check.py']

As you see it didn’t showed the -h argument I supplied to it.

My check.py

import sys
print "hello"
print sys.argv

If I remove print sys.argv from the above mentioned python script it work fine in both cases I mentioned above i.e, it prints “hello” just fine.

So, my question is how does one execute a python script that accepts some command line arguments after the script is added to environment variable.

My purpose is to execute my python script from anywhere in the windows command prompt which is somewhat similar to chmod +x check.py.

I tried the chmod option in cygwin it works fine for both cases.

Cygwin output

noob@noob-PC ~
$ chmod +x check.py

noob@noob-PC ~
$ ./check.py h
['./check.py', 'h']
  • 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-06-02T11:11:56+00:00Added an answer on June 2, 2026 at 11:11 am

    Windows does not have a notion of executable script files with the interpreter given as a #!, so what you intend to do cannot work. What Windows does is to call the WinAPI function ShellExecute which does the following:

    However, it is more commonly used to launch an application that
    operates on a particular file. For instance, .txt files can be opened
    by Microsoft WordPad. The open verb for a .txt file would thus
    correspond to something like the following command:

    "C:\Program Files\Windows NT\Accessories\Wordpad.exe" "%1"
    

    see MSDN

    As you can see, only the first parameter is supplied to the application. In your case, this translates to something along the lines of:

    "C:\Program Files\Python\Python.exe" "D:\github\Miscellaneous-Programs\Python\check.py"
    

    What you can do to avoid this is to create a little .bat file named check.bat:

    python check.py %*
    

    (See this SO question for more details. You might also have to supply an absolute path for check.py or python if they cannot be found)

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

Sidebar

Related Questions

I know the title of this question is not very descriptive, but I didn't
i don't know good title but heres the explain i have this link <a
I know the title does not sound very descriptive, but it is the best
I don't know if the Title of this post makes sense, but here's a
Say my list is {1,2,3,4} My title may not be descriptive enough but here
Let me start off by saying I know this is probably not the correct
Sorry about the title. I do realize it's not very descriptive. :| Here is
Sorry if the title is not that specific, but I don't know how else
First off, I know the title is generic and not fitting. I just couldn't
I am sorry for the title but I really do not know how to

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.