我在Windows 7上使用IEXPRESS准备了一个exe文件,在cmd中运行Python脚本,通过ftp将一些数据复制到产品中。
运行exe文件时,将打开命令提示符并显示描述该进程的文本。这很好用。但现在我想将所有cmd数据重定向到文本文件。
示例:我运行文件“se.exe”。它打开cmd并显示“This is stackoverflow.com。”,然后关闭。我希望将此文本重定向到文本文件。
有没有办法在不修改Python脚本的情况下做到这一点?
任何建议都会很明显。
import os
import sys
import string
import time
from ftplib import FTP
import filecmp
#Check for Ethernet connection
try:
ftp = FTP('192.168.2.10','FACTORY','Factory','\0',3)
except:
print 'Communication cannot be established...'
print 'Check Ethernet connection or IP address and retry.'
os.system('pause')
sys.exit()
ftp.close();
time.sleep(3)
sys.exit()
答案 0 :(得分:1)