title: Added subprocess, error that variable is not defined
body: <p>My script gets arguments such as</p>
  
  <pre><code>C:\&gt; python lookup.py "sender-ip=10.10.10.10"
  </code></pre>
  
  <p>And would take sender-ip and find wmi information</p>
  
  <p>Now I added a ping subprocess to pint the machine BEFORE attempting to get wmi information and I get following error</p>
  
  <pre><code>C:\&gt; python lookup.py "sender-ip=10.10.10.10"
  Traceback (most recent call last):
    File "lookup.py", line 10, in &lt;module&gt;
      ["ping", "-n", "1", userIP],
  NameError: name 'userIP' is not defined
  </code></pre>
  
  <p>Then I tried to define userIP global variable at the beginning of the beginning of the program, but I get error </p>
  
  <pre><code>C:\&gt; python lookup.py "sender-ip=10.10.10.10"
  Traceback (most recent call last):
    File "lookup.py", line 10, in &lt;module&gt;
      ["ping", "-n", "1", userIP],
  NameError: global name 'userIP' is not defined
  </code></pre>
  
  <p>Here is the program(without global declaration)</p>
  
  <pre><code># import statements
  import sys, wmi, subprocess
  
  # subprocess
  ping = subprocess.Popen(
      ["ping", "-n", "1", userIP],
      stdout = subprocess.PIPE,
      stderr = subprocess.PIPE
  )
  
  # get the arguments and extract user's IP address
  argument = sys.argv[1]
  attr_map = dict(item.strip().split('=') for item in argument.split(','))
  userIP =  attr_map['sender-ip']
  print userIP
  
  # can we ping the user's IP address?
  out, error = ping.communicate()
  
  # if we cannot ping user's IP address then print error message and exit program
  if out.find("Reply from") == -1:
      print userIP, "is NOT pingable."
      sys.exit()
  
  # remaining lines will execute if we can ping user's IP address
  c = wmi.WMI(userIP)
  for os in c.Win32_OperatingSystem():
    print os.Caption
  </code></pre>