【问题标题】:Subprocess not working ~ Opening Game Script w/ a Menu Script子进程不工作〜使用菜单脚本打开游戏脚本
【发布时间】:2014-01-22 05:37:06
【问题描述】:

当我使用子进程通过菜单脚本打开我的游戏脚本时,我收到一个奇怪的错误,即使我尝试重新安装 python 或 pygame,我似乎也无法修复。我是在错误地使用代码还是什么?

~信息~ Python 版本 2.7.6 Pygame 版本 1.9.1

~错误给定~

> > Traceback (most recent call last):   File "C:\Users\Jason\Desktop\Maze\menu.py", line 22, in <module>
>     subprocess = Popen(['swfdump', 'main.py', '-d'], stdout=PIPE)   File "C:\Python27\lib\subprocess.py", line 709, in __init__
>     errread, errwrite)   File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
>     startupinfo) WindowsError: [Error 2] The system cannot find the file specified

~ 我用于菜单的代码~

    import pygame
import dumbmenu as dm
pygame.init()
from subprocess import Popen, PIPE

# Just a few static variables
red   = 255,  0,  0
green =   0,255,  0
blue  =   0,  0,255

size = width, height = 340,240  
screen = pygame.display.set_mode(size)
screen.fill(blue)
pygame.display.update()
pygame.key.set_repeat(500,30)

choose = dm.dumbmenu(screen, [
                        'Start Game',
                        'Quit Game'], 64,64,None,32,1.4,green,red)

if choose == 0:
    pprocess = Popen(['swfdump', 'main.py', '-d'], stdout=PIPE)
    stdout, stderr = process.communicate()
elif choose == 1:    
    pygame.quit()
exit()

【问题讨论】:

    标签: python python-2.7 pygame


    【解决方案1】:

    Popen() 的第一个参数是 ['swfdump', 'main.py', '-d'],它将执行 一个名为 swfdump 的东西,带有参数 main.py -d。我怀疑,你想要一些不同的东西。来自the fine documentation

    args 应该是一系列程序参数或单个字符串。默认情况下,如果 args 是一个序列,则要执行的程序是 args 中的第一项。

    【讨论】:

      【解决方案2】:

      试试:

      pprocess = Popen('swfdump main.py -d', shell=True, stdout=PIPE)
      

      看看这是否有效。如果您真的想使用列表,我认为可以使用['swfdump main.py -d',]shell=False

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-02
        • 1970-01-01
        • 2011-11-18
        • 1970-01-01
        • 2015-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多