![]() |
error on bat file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: error on bat file (/thread-12488.html) |
error on bat file - Sanlus - Aug-27-2018 so today i tried to create a bat file, and the code is like this: #! python3 @py.exe C:\Users\MSI\AppData\Local\Programs\Python\Python37-32\Automate the Boring Stuff with Python Course\searchmap.py %*and the system popped out a SyntaxError box saying invalid syntax, highlighting the C in C:\ part. i tried to get rid of first line or change the @py.exe to just @py but nothing is working. RE: error on bat file - Larz60+ - Aug-27-2018 what is py.exe? normally python is executed from command line simply with python followed by script name. RE: error on bat file - Sanlus - Aug-27-2018 (Aug-27-2018, 11:21 AM)Larz60+ Wrote: what is py.exe? normally python is executed from command line simply with python followed by script name.so how should i write it? i learnt @py.exe from videos, rip RE: error on bat file - Larz60+ - Aug-27-2018 I don't have enough information on your system to answer properly. From a 'command' prompt AKA terminal prompt, type: python -Vand post results RE: error on bat file - Sanlus - Aug-27-2018 (Aug-27-2018, 11:45 AM)Larz60+ Wrote: I don't have enough information on your system to answer properly. From a 'command' prompt AKA terminal prompt, type:its Python 3.7.0python -Vand post results RE: error on bat file - Larz60+ - Aug-27-2018 then you should use: python searchmap.pyWith path if not in system path RE: error on bat file - Sanlus - Aug-27-2018 (Aug-27-2018, 12:13 PM)Larz60+ Wrote: then you should use:ive tried python and @python, neither worked. still the same error messagepython searchmap.pyWith path if not in system path (Aug-27-2018, 12:13 PM)Larz60+ Wrote: then you should use:where would i need to put this code inpython searchmap.pyWith path if not in system path RE: error on bat file - snippsat - Aug-27-2018 py.exe get installed in Windows folder when install Python37.Can be used to accessing previous version or current,can also install with pip to all version installed.Example: # Python version set in Windows Path C:\>python -V Python 3.7.0 # Can also access with py C:\>py -3.7 -V Python 3.7.0 # Older version i have C:\>py -2.7 -V Python 2.7.9 C:\>py -3.4 -V Python 3.4.2 C:\>py -3.5 -V Python 3.5.2 C:\>py -3.6 -V Python 3.6.4Use py to install with pip to eg 2.7. λ py -2.7 -m pip install logzero Requirement already satisfied: logzero in c:\python27\lib\site-packagesMaking bat hello.bat .Use python main version,pause in bat so cmd window doesn't close immediately.Can also put this last in code input('Press Enter to exit') .@echo off python C:/foo/hello.py %* pauseIf want to run 2.7 in a bat file,then use py .@echo off py -2.7 C:/foo/hello.py %* pause RE: error on bat file - Sanlus - Aug-28-2018 (Aug-27-2018, 02:47 PM)snippsat Wrote:now i have syntax error on off in @echo off. rip RE: error on bat file - snippsat - Aug-28-2018 (Aug-28-2018, 05:42 AM)Sanlus Wrote: now i have syntax error on off in @echo off. ripYou are making a .bat file and not run it with Python?Batch file : ECHO command A run i cmd. E:\>cd E:\div_code\bat # look at files E:\div_code\bat>dir Volume in drive E is 2 TB Volume Serial Number is 3433-29C0 Directory of E:\div_code\bat 28.08.2018 15:57 <DIR> . 28.08.2018 15:57 <DIR> .. 27.08.2018 16:28 45 hello.bat 27.08.2018 16:27 46 hello_27.bat 2 File(s) 91 bytes 2 Dir(s) 222 956 498 944 bytes free # Content of hello.bat E:\div_code\bat>more hello.bat @echo off python C:/foo/hello.py %* pause # Run hello.bat E:\div_code\bat>hello.bat hello world Press any key to continue . . . # Content of hello_27.bat E:\div_code\bat>more hello_27.bat @echo off py -2.7 C:/foo/hello.py %* pause # Run hello_27.bat E:\div_code\bat>hello_27.bat hello world Press any key to continue . . . hello.py that .bat files run:print('hello world') #input('Press enter to exit') |