-1

I am struggling with an apparently obvious issue. I've been practising python and I have a few scripts and I am trying to run them from windows 10 execute command (WIN + R).

I am doing this by creating a BATCH file of the script, and in theory the file should run with a simple "py script" in the WIN+R window. But it does not, it simply flashes the CMD window for a sec and then disappear.

Everything seems to be set up correctly, I can run the script from CMD, BATCH file are OK (they run with a double click, I included the @pause at the end), the folder where BATCH are is in the env. variables PATH.

So i really don't get what is wrong. Note that If I type the full path in the WIN+R window it works, but that takes quite some time..

Any hints?

A BIG thank you :)

EDIT: thanks for the replies, here is the batch:

@py script.py
@pause

It works on double click.

Blackchat83
  • 85
  • 1
  • 6
  • *"Everything seems to be set up correctly"* – well, obviously not as it doesn't work; but if you don't show anything, how should we know?? – aschipfl Jan 10 '20 at 19:53
  • If your batch file is in `%PATH%` and you're running it inside the **Run** dialog with just its name, then the batch file should work fine, subject to you using its extension, or that extension being included within the `%PATHEXT%` variable value. The code within the batch file however may not be running, and to determine that we'd need to see its content. Please [edit your question](https://stackoverflow.com/posts/59687516/edit) to include its code formatted accordingly using the **`{}`** button. – Compo Jan 10 '20 at 20:10

3 Answers3

0

Ctrl + R => opens run window.

Type in "cmd"

If you have python installed with Path.

python <yourscript.py>

should run just fine.

Otherwise, Run as below.

path/to/python/python.exe <yourscript.py>

Hope you did the same as above. If the bat runs and closes in a flash. That is not an issue. It happens.

Have a sleep in your bat as well. If you're running on bat.

Add below after your python script execution.

It will make your bat script wait for a thirty seconds before closing and you can verify your stdout.

timeout /t 30
High-Octane
  • 1,104
  • 5
  • 19
0

On Windows, executing Python scripts directly, i.e. without calling python before, can be tricky. Often Windows will just open your default Python editor to show you the file, because the .py extension is registered to this editor.

see this post for more info: How to execute Python scripts in Windows?

mattmilten
  • 6,242
  • 3
  • 35
  • 65
0

You should create a batch file as follows...

@py -3 E:\FOLDER\SUBFOLDER\FILE.py %* @pause

I have both python 2 and python 3 so I use py -3 as for me py will run Python 2 The ending %* is important

Abdullah Ashraf
  • 101
  • 1
  • 5