Python Forum

Full Version: error on bat file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
what is py.exe?
normally python is executed from command line simply with python followed by script name.
(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
I don't have enough information on your system to answer properly.
From a 'command' prompt AKA terminal prompt, type:
python -V
and post results
(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:
 python -V 
and post results
its Python 3.7.0
then you should use:
python searchmap.py
With path if not in system path
(Aug-27-2018, 12:13 PM)Larz60+ Wrote: [ -> ]then you should use:
 python searchmap.py 
With path if not in system path
ive tried python and @python, neither worked. still the same error message

(Aug-27-2018, 12:13 PM)Larz60+ Wrote: [ -> ]then you should use:
 python searchmap.py 
With path if not in system path
where would i need to put this code in
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.4
Use 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-packages
Making 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 %*
pause
If want to run 2.7 in a bat file,then use py.
@echo off
py -2.7 C:/foo/hello.py %*
pause
(Aug-27-2018, 02:47 PM)snippsat Wrote: [ -> ]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.4 
Use 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-packages
Making 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 %* pause 
If want to run 2.7 in a bat file,then use py.
@echo off py -2.7 C:/foo/hello.py %* pause
now i have syntax error on off in @echo off. rip
(Aug-28-2018, 05:42 AM)Sanlus Wrote: [ -> ]now i have syntax error on off in @echo off. rip
You 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')