【发布时间】:2019-11-28 17:49:10
【问题描述】:
我想从批处理文件运行交互式 Python 程序。我在“pythonw.exe 还是 python.exe?”这个问题中找到了 the answer。有帮助,但并不是我想到的所有问题都得到了解决。我决定尝试使用con:。
下面展示了我实现的那种交互:
Microsoft Windows [Version 10.0.18362.476]
(c) 2019 Microsoft Corporation. All rights reserved.
c:\sjt\PY\NEWER>type call_py.bat
@echo off
call python c:\sjt\py\newer\testout.py 1>con: 2>con:
c:\sjt\PY\NEWER>type testout.py
print ("Print works if you can see this.")
strwaiter = raw_input ("raw_input prompt: ")
print ("This string was received by strwaiter in response to the prompt: " + strwaiter)
c:\sjt\PY\NEWER>call_py
Print works if you can see this.
raw_input prompt: Here is my response.
This string was received by strwaiter in response to the prompt: Here is my response.
c:\sjt\PY\NEWER>
我尝试再次运行call_py.bat,但它调用pythonw 而不是python,此尝试没有产生预期的结果。
另外,在我的实验过程中,我尝试在没有1 和2 重定向的情况下调用python。同样,这也没有成功。
我尝试为该问题的相关答案添加评论,但由于我没有所需的声誉而失败。我正在发布这个问题。
我的实验是否对这个问题的答案有所补充?
鉴于我对该帖子中给出的技术细节一无所知,为什么在我的批处理文件中调用
python有效(使用这些重定向)但调用pythonw却不行?
【问题讨论】:
标签: python batch-file interactive