Python .py文件已转换为.exe。但无法达到预期的效果

Python .py文件已转换为.exe。但无法达到预期的效果,python,module,executable,Python,Module,Executable,我尝试了以下代码: import os def test1(): os.system('cmd.exe /k ipconfig') def main(): task = raw_input('Enter your choice [1] :') if task=="1": test1() select=raw_input("Select y if you want to run the test again (y/n)")

我尝试了以下代码:

import os

def test1():

    os.system('cmd.exe /k ipconfig')

def main():

    task = raw_input('Enter your choice [1] :')
    if task=="1":
        test1()
        select=raw_input("Select y if you want to run the test again (y/n)")    
        if select=="y":
            main()
        else:
            print('No need to run the test again')

    else:
        print('Enter valid input')

main()

如果我在Python Idle中执行此命令,我得到了预期的结果(在关闭命令窗口后也会弹出命令窗口,它要求“如果要再次运行测试,请选择y(y/n)”),但在将此脚本设置为.exe(可执行)文件后,我无法获得命令窗口弹出窗口(没有从.exe中获得预期的输出,因为我从Python Idle中获得)。如何解决此问题……?

因此,从您的代码来看,您似乎希望通过运行
os.system('cmd.exe/k ipconfig')来打开一个新的cmd,显示ipconfig。

但是运行
cmd.exe/k ipconfig
不会打开新窗口

相反,请尝试使用
start cmd/k ipconfig
,但这不会等待cmd关闭。如果要等待它关闭,请询问是否要再次测试,请尝试
start/wait cmd/k ipconfig


注意:确保在
dist
文件夹中运行.exe

如何将py转换为exe?@dinespundkar他正在使用pyinstaller。exe@DineshPundkar是的,正如Davit所说,使用pyinstaller.exe将.py转换为。exe@DineshPundkarPlz将上述代码中的这些行更改为“input”,而不是“raw_input”,并从cmd提示符…task=inp执行ut('输入您的选择[1]:')和select=input(“如果您想再次运行测试,请选择y(y/n)”)。希望您能得到结果,但不要像从python编辑器中获得结果那样。感谢您的响应。将尝试此操作并返回结果。使用此“操作系统”获得预期结果。。再次感谢:)('ping 127.0.0.1-t>>new.txt')。我可以在new.txt文档中获得ping结果。如果流输出是这样的,如何在命令窗口和文本文件中同时获得ping结果…?您可以始终将其保存在新的.txt文件中,然后在控制台中通过说
os.system('type new.txt')