Jayaram
Jayaram

Reputation: 6606

Executing a Python script from the command line in Windows 7

I seem to be having a problem with executing a Python script from a Win+R terminal.

I completed the following steps:

  1. Used the shebang line before typing my script for all .py files. An example of what I did below for a script called Primefactorization.py.

    #! python3
    
  2. I created a batch file in the same folder with the same name and input the following code:

    @python.exe C:\Python Scripts\Primefactorization.py %*
    
  3. I added the path (C:\Python Scripts) to the PATH variable in the environment variables window.

  4. When I try to invoke the script using the Run command in Windows 7, the shell opens and immediately disappears.

  5. Based on a past answer to a similar problem on Stack Overflow, I also added the following code prompting the user for input before exiting. But that doesn't seem to work.

    x = input('press enter to close')
    

Could you please let me know where the problem might be?

Upvotes: 3

Views: 2318

Answers (1)

Zenadix
Zenadix

Reputation: 16279

Your path has a space in it. Enclose it in double quotes. For example:

python.exe "C:\Python Scripts\Primefactorization.py"

Upvotes: 1

Related Questions