简体   繁体   English

如何使用Windows Batch脚本执行python terminal命令?

[英]How can you execute python terminal command using a Windows Batch script?

So using Windows batch scripting I know we can open the python interpreter as follows and execute a python script: 因此,使用Windows批处理脚本,我知道我们可以如下所示打开python解释器并执行python脚本:

c:\python27\python.exe c:\documents\python_script.py

In turn, I know it is possible to just open the python interpreter just by typing: 反过来,我知道可以通过键入以下内容来打开python解释器:

c:\python27\python.exe

However, using a batch script is it possible to "communicate" with the python interpreter and send it commands to execute ie: 但是,使用批处理脚本可以与python解释器“通信”并发送命令以执行,即:

c:\python27\python.exe import os

and then to exit from the interpreter as such: 然后像这样从解释器退出:

c:\python27\python.exe exit()

Any insight would be kindly appreciated. 任何见解将不胜感激。

Thankyou 谢谢

您可以使用-c选项

c:\python27\python.exe -c "import sys; print sys.version"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Python脚本在终端中执行命令? - How to execute a command in the terminal from a Python script? 如何将python脚本加载到内存中并像执行命令行一样执行它? - How can you load a python script into memory and execute it as if it was the command line? Python将在Unix而非Windows上运行。 如何在终端中运行外部python命令? - Python will run in Unix, not Windows. How can you run an external python command in terminal? 如何:Python脚本每小时执行一次终端命令? - How: Python Script to execute Terminal Command every hour? 如何使用 python 命令执行 python 脚本 - How to execute python script using python command 您可以在不使用 linux 上的终端的情况下执行 python 文件吗? - Can you execute python files without using the terminal on linux? 执行一个从python 2.6脚本中的终端接收参数的终端命令 - Execute a terminal command that takes an argument from terminal in python a 2.6 script 如何使用 python 在指定目录中执行终端命令? - How to execute a terminal command within a specified directory using python? 我如何通过Java中的终端执行python脚本 - how can i execute python script via terminal in Java 使用 python 对当前终端执行导出命令 - execute export command to current terminal using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM