2

I was using os.system for shell commands until I discovered it's deprecated. So I am trying to switch to using subprocess. Here are my uses:

command = genConfig.MODETECT_SWITCH_COMMAND.append(state)
subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]

MODETECT_SWITCH_COMMAND = ["zmpkg.pl"]

and some regular pings:

command = genConfig.PING_COMMAND.append(host)
response = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]
if "unreachable" in response or "timed out" in response:
    response = False
else:
    response = True
    break

PING_COMMAND = ["ping", "-c 1 -W 1"]

Everywhere I do these things, I get this error:

...tracebacks...
  File "/usr/lib/python2.7/subprocess.py", line 1198, in _execute_child
    args = list(args)
TypeError: 'NoneType' object is not iterable

And I can't figure out why. I've rechecked my use of subprocess.popen multiple places and it seems to be correct. What might I be doing incorrectly? Thanks.

1 Answer 1

4

You have this:

MODETECT_SWITCH_COMMAND = ["zmpkg.pl"]

And when you do this:

command = genConfig.MODETECT_SWITCH_COMMAND.append(state)

You are assigning to command the output of a list.append call, which operates in place and returns None.

That is, it looks like you are assigning command = None.

subprocess module is confused because it expects the first positional argument to be an iterable, not None.

1
  • Rookie mistake -- thanks. I have got to remember that .append changes the list in place, I always mix-up which command do things in-place and which give you a copy.
    – linus72982
    Apr 9, 2015 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.