.py文件转换为.exe。但无法得到预期的结果

时间:2017-10-13 04:57:09

标签: 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)")    
        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(可执行文件)文件后,我无法弹出命令窗口(因为我从Python空闲中获取,所以未获得.exe的预期输出)。如何解决这个问题....?

1 个答案:

答案 0 :(得分:0)

因此,从您的代码中,您似乎想通过运行os.system('cmd.exe /k ipconfig')

打开一个显示ipconfig的新cmd

但是正在运行cmd.exe /k ipconfig将无法打开新窗口。

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

注意:确保在dist文件夹

中运行.exe
相关问题