Python Forum
batch file for running python scipt in Windows shell
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
batch file for running python scipt in Windows shell
#1
Hi,

I am doing an assignement in a Python learning book in which i have to run my Python script in the Windos shell. It says that i have to make a batch file containing:

Quote:@py.exe C:\yourpath\PythonScript.py %*
@pause

What is the function of this bat file?
Reply
#2
The @ in a batch file is suppressing the echoing of the command.
Often in batch files the following pattern is used, to switch the echoing of commands globally off:
@echo off
py.exe is the program, which finds the latest Python Interpreter on well-known paths.
C:\yourpath\PythonScript.py is the program itself.
The %* is for arguments.
google Wrote:%* expands to the complete list of arguments passed to the script. You typically use it when you want to call some other program or script and pass the same arguments that were passed to your script. The %* modifier is a unique modifier that represents all arguments passed in a batch file.

The command pause will be executed after the python program has been finished. The command pause waits for a key press.
This is often used to see debug output from a broken program. If it was not run direct in a terminal, the new terminal will instantly close, and you've no time to read the Exceptions.
tester_V likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
Thank you for the info. But what is the purpose of this batch file, as i can already run the .py program from the system shell?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error "cannot identify image file" part way through running hatflyer 0 612 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  Help creating shell scrip for python file marciokoko 10 1,254 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,003 Jun-29-2023, 11:57 AM
Last Post: gologica
  Python script running under windows over nssm.exe JaroslavZ 0 671 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Launch Python IDLE Shell from terminal Pavel_47 5 1,143 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Web project and running a .py file emont 0 619 Dec-11-2022, 11:15 PM
Last Post: emont
  Running A Parser In VSCode - And Write The Results Into A Csv-File apollo 5 4,533 Jan-14-2021, 08:58 PM
Last Post: snippsat
  Sound Approach for Running a Shell Command? matt_the_hall 8 3,254 Dec-14-2020, 02:52 PM
Last Post: matt_the_hall
  Using a .bat file to execute simple anaconda commands in Windows 10 gacg1 0 4,620 Nov-30-2020, 03:24 PM
Last Post: gacg1
  How to make a Python program run in a dos shell (cmd) Pedroski55 2 2,255 Nov-09-2020, 10:17 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020