无法在python pysys中使用helper.py启动该过程

时间:2012-11-22 10:05:45

标签: python windows

import sys, os, os.path, re, string, time, thread, logging, copy, math, stat

from pysys import log
from pysys.constants import *

from pysys.process.helper import ProcessWrapper

def __stringToUnicode( s):
        """ Converts a unicode string or a utf-8 bit string into a unicode string. 

        """
        if isinstance(s, unicode):
            return s
        else:
            return unicode(s, "utf8")
environ ={}
for key in environ: environ[__stringToUnicode(key)] = __stringToUnicode(environ[key])

process = ProcessWrapper("C:\\Program Files\\Mozilla Firefox\\firefox", arguments=None, environs=environ, workingDir=None, state=FOREGROUND, timeout=None, stdout=None, stderr=None)
process.start()

我收到此错误..

  process = ProcessWrapper("notepad", arguments=None, environs=environ, workingDir=None, state=FOREGROUND, timeout=None, stdout=None, stderr=None)
  File "C:\Python27\lib\site-packages\pysys\process\plat-win32\helper.py", line 105, in __init__
    for a in self.arguments: log.debug("  argument     : %s", a)
TypeError: 'NoneType' object is not iterable

我是pysys的新手。请帮帮我。

2 个答案:

答案 0 :(得分:1)

以下内容适用于我尝试时 - 不确定问题是否在unicode翻译中。

import logging
from pysys.constants import *
from pysys import stdoutHandler
from pysys.process.helper import ProcessWrapper

stdoutHandler.setLevel(logging.DEBUG)

command="\\Program Files\\Mozilla Firefox\\firefox.exe"
process = ProcessWrapper(command, arguments=[], environs=os.environ, workingDir=os.getcwd(), state=BACKGROUND, timeout=None)
process.start()

答案 1 :(得分:0)

显然,ProcessWrapper()期望arguments是可迭代的(列表或元组会这样做)。

使用None(空元组)而不是()

但请注意,workingDir 设置为字符串。使用os.getcwd()获得理智的默认值。还必须将timeout设置为等待的整数秒数。我猜60秒(一分钟)就像任何东西一样好。

您可以省略 stdoutstderr参数,并将其保留为默认值:

process = ProcessWrapper("C:\\Program Files\\Mozilla Firefox\\firefox", arguments=() environs=environ, workingDir=os.getcwd(), state=FOREGROUND, timeout=60)