user1844634
user1844634

Reputation: 1263

Unable to start the process with helper.py in python pysys

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

I am getting this error..

  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

I am new to pysys. please help me out.

Upvotes: 0

Views: 105

Answers (2)

moraygrieve
moraygrieve

Reputation: 466

The below works for me when I try it - not sure if the issue was in the unicode translation.

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

Upvotes: 1

Martijn Pieters
Martijn Pieters

Reputation: 1123770

Clearly, ProcessWrapper() expects arguments to be an iterable (a list or a tuple would do).

Instead of None, use () (an empty tuple).

Note however, that workingDir should be set to a string. Use os.getcwd() for a sane default. timeout also has to be set, to an integer count of seconds to wait. I guess 60 seconds (a full minute) is as good as anything.

You can omit the stdout and stderr arguments and leave those at their defaults:

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

Upvotes: 0

Related Questions