如何在bat文件中插入python代码?

时间:2017-01-13 19:22:54

标签: batch-file ipython

想插入python代码 或在Windows bat文件中运行ipython代码 (不在单独的.py文件中)。

搜索后,找不到任何解决方案。

编辑: 这是针对ipython代码(不是python)。

2 个答案:

答案 0 :(得分:6)

试试这个(batch-python polyglot脚本):

new Student(0);

0<0# : ^ ''' @echo off echo batch code python %~f0 %* exit /b 0 ''' print("python code") 分别开始和结束python多行注释。

'''更有趣 - 由于批处理中的重定向优先级,它将被批处理脚本解释为0<0# : ^,这是一个标签,执行将不会显示在屏幕上。最后的插入符将转义为新行,第二行将附加到第一行。对于python,它将是:0<0# ^语句和内联注释的开始。

信用额转到siberia-man

答案 1 :(得分:0)

另一种解决方案是:

'''
@echo off & python -x "%~f0" %* & goto :eof
print "Hello 123"
'''