[英]Printing output of python script to Windows console, when running via batch file
I have tried to look at other resources on SO but none seem to solve my problem: 我试图查看SO上的其他资源,但似乎没有一个能解决我的问题:
Executing Python Script From Command Line is Hiding Print Statements 从命令行执行Python脚本隐藏了打印语句
How do I write output in same place on the console? 如何在控制台的相同位置写入输出?
Python script doesn't print output in command prompt Python脚本无法在命令提示符下打印输出
I have a .py script that I'm executing via a batch file. 我有一个通过批处理文件执行的.py脚本。 Within my .py script, I have a few different attempts at printing output to the console window.
在我的.py脚本中,我做了几次尝试将输出打印到控制台窗口的尝试。 When I run the batch file and the console window pops up, I don't see the print output.
运行批处理文件并弹出控制台窗口时,看不到打印输出。 I don't have any other problems with executing the program, and I've otherwise used python and batch files to generate file output, etc.
我在执行程序时没有其他问题,否则我使用了python和批处理文件来生成文件输出,等等。
This is my .py script, I'm trying three different ways of writing output based on other SO articles: 这是我的.py脚本,我正在尝试基于其他SO文章的三种不同的写输出方式:
import sys
# Attempt 1
print('hello')
# Attempt 2
sys.stdout.write('hello')
# Attempt 3
if __name__ == '__main__':
print('hello')
My batch file: 我的批处理文件:
"C:\Program Files\Anaconda3\pythonw.exe" "\\*********\printTest.py"
PAUSE
My output, none of my desired 'hello' output displays. 我的输出,没有显示我想要的“ hello”输出。 I've edited the location of my script but the directory has been triple checked and is correct:
我已经编辑了脚本的位置,但是目录已被三重检查,并且是正确的:
C:\Windows>"C:\Program Files\Anaconda3\pythonw.exe" "\\********\printTest.py"
C:\Windows>PAUSE
Press any key to continue . . .
How do I get 'hello' to print to the console? 如何获得“ hello”打印到控制台?
You're running "pythonw.exe", which is for graphical user interface (GUI) scripts, not console scripts. 您正在运行“ pythonw.exe”,它用于图形用户界面(GUI)脚本,而不是控制台脚本。 Run "python.exe" to inherit CMD's console for standard I/O.
运行“ python.exe”以继承CMD的标准I / O控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.