Python Forum
Creating a bat file to call Python from command line
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a bat file to call Python from command line
#1
I have created a .bat file containing
@echo off
set PATH=C:\Users\Dimitris\AppData\Local\Programs\Python\Python36-32;%SystemRoot%\System32
C:\Users\Dimitris\Documents
cd \Programmes
cmd.exe
According to the book I am working this should call the command line from where I could program in Python language (sure I know about IDLE and Python shell!). I just want to figure out what I am doing wrong. Thank you very much in advance for your help.
Reply
#2
Yes, that creates a command line in which you can call the Python interpreter. But it doesn't extend the PATH to include Python, it replaces your whole path so you can end up missing things. Do all these directories exist?
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
(Feb-18-2017, 12:18 AM)dimitrisana Wrote: I have created a .bat file containing
@echo off
set PATH=C:\Users\Dimitris\AppData\Local\Programs\Python\Python36-32;%SystemRoot%\System32
C:\Users\Dimitris\Documents
cd \Programmes
cmd.exe
According to the book I am working this should call the command line from where I could program in Python language (sure I know about IDLE and Python shell!). I just want to figure out what I am doing wrong. Thank you very much in advance for your help.

Not sure which book you are using, but let's presume you have Python installed correctly (including it's entry's in your environmental variables.  If that is true, then your .bat file need only be:
cmd /C c:\python36\python.exe
Note that the location of your 'python.exe' may be located in a different directory, if so, just replace the correct directory instead of "c:\python36".

Running the .bat will open the python interpreter and you can go ahead and start typing.

Output:
C:\Python>cmd /C c:\python36\python.exe Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 808 Yesterday, 05:47 AM
Last Post: Bronjer
  Is possible to run the python command to call python script on linux? cuten222 6 733 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  Help creating shell scrip for python file marciokoko 10 1,366 Sep-16-2023, 09:46 PM
Last Post: snippsat
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,578 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Getting last line of each line occurrence in a file tester_V 1 869 Jan-31-2023, 09:29 PM
Last Post: deanhystad
  Creating csv files from Excel file azizrasul 40 5,621 Nov-03-2022, 08:33 PM
Last Post: azizrasul
  Command line argument issue space issue mg24 5 1,340 Oct-26-2022, 11:05 PM
Last Post: Yoriz
  accept command line argument mg24 5 1,316 Sep-27-2022, 05:58 PM
Last Post: snippsat
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,383 Sep-27-2022, 01:38 PM
Last Post: buran
  Print to a New Line when Appending File DaveG 0 1,224 Mar-30-2022, 04:14 AM
Last Post: DaveG

Forum Jump:

User Panel Messages

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