How to get subprocess.Popen to work correctly?
<p>I'm trying get <code>subprocess.Popen()</code> to work correctly, but for some reason the returned value is completely wrong.</p>

<p>The script opens an FTP connection script that downloads files from a server, then returns a tuple of the successful and unsuccessfully downloaded files. This script has worked before using <code>subprocess.call()</code>, but I want to use <code>Popen()</code> so that the script it's calling is in another thread and doesn't interfere with the main program.</p>

<p>Here is my main class:</p>

<pre><code>def FTPDownload(self):
    try:
        ftpReq = subprocess.Popen(['Python', mw._['cwd']+"dwnldMedia.py"],
                                  shell=True,
                                  stdout=subprocess.PIPE)
        successful, unsuccessful = ftpReq.communicate()
        self.consPrompt("Successful:\t"+str(successful))
        self.consPrompt("Unsuccessful:\t"+str(unsuccessful))
    except subprocess.CalledProcessError as e:
        self.consPrompt((cp._['E0']).format(str(e)))
</code></pre>

<p>and here is <code>dwnldMedia.py</code> (<code>__init__</code> calls <code>download()</code>):</p>

<pre><code>def download(self):
    #print("connected")
    self.server = FTP(**self.serverDetails)
    self.server.login(**self.userDetails)

    self.server.cwd("/public_html/uploads") #changing to /pub/unix
    #print "File List: \n"
    files = []
    successful = [0]
    unsuccessful = [0]
    self.server.retrlines("NLST",files.append)
    for f in files:
        if(f != '.' and f != '..'):
            #print("downloading:\t"+f)
            local_filename = os.path.join(mw._['cwd']+"media", f)
            with open(local_filename, "wb") as i:
                self.server.retrbinary("RETR " + f, i.write)
                #print("\t| Success")
                successful.append(f)
    for f in files:
        if(f != '.' and f != '..' and f not in successful):
            unsuccessful.append(f)
    return (successful, unsuccessful)
</code></pre>

<p>The output I get is:</p>

<pre class="lang-none prettyprint-override"><code>Successful:
Unsuccessful:   None
</code></pre>

<p>Where <code>successful</code> has a value of <code>None</code>.</p>