子进程不工作~打开带有菜单脚本的游戏脚本

2024-04-25 06:38:47 发布

您现在位置:Python中文网/ 问答频道 /正文

当我使用subprocess使用菜单脚本打开游戏脚本时,我遇到了一个奇怪的错误,即使我尝试重新安装python或pygame,似乎也无法修复。我是不是用错代码了?你知道吗

~信息~ Python版本2.7.6 Pygame Verison 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

~z~我用的菜单代码~

    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()

Tags: inpyimport脚本错误stdoutline菜单
2条回答

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

args should be a sequence of program arguments or else a single string. By default, the program to execute is the first item in args if args is a sequence.

尝试:

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

看看这样行不行。如果你真的想用一个列表,你可以用['swfdump main.py -d',]shell=False来代替。你知道吗

相关问题 更多 >