Last active
October 21, 2024 22:11
-
-
Save jadient/9849314 to your computer and use it in GitHub Desktop.
Run python code directly from a batch file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off & python -x "%~f0" %* & goto :eof | |
# ========================================================== | |
# one way to place python script in a batch file | |
# place python code below (no need for .py file) | |
# ========================================================== | |
import sys | |
print "Hello World!" | |
for i,a in enumerate(sys.argv): | |
print "argv[%d]=%s" % (i,a) |
The problem is I don't want to include or embed another .bat file. I want all these in one single file because I will be publishing the batch file as an .exe file to stop others from stealing code and I don't want them seeing the included files.
nice
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run commands before or after, create a new batch file that calls this batch file, for example:
python reads the entire contents of
batchfile.bat
and skips the first line. there's no way to change that.