0

I've starting a script but for some reason it's not working as intended.

I'm trying to cycle through a folder going over all of the files in the folder and making it following command in command prompt for each file:

adb install -r C:\foldername\filename.apk

I want the command to run as a window rather than in the background so that I can see the ordinary command prompt window.

I'm also then waiting until all of the cmd.exe windows have gone before starting a new batch of 5 commands.

Here's what I have so far, I think the problem is to do with how I am running the command, I've tried a few types (included two in this, os.system() and subprocess.popen()

import os
import time
import subprocess
import shutil

AppsNewDir = "C:\\NewApps"
counter = 0

def is_process_running(process):
    n = 0  # number of instances of the program running
    prog = [line.split() for line in subprocess.check_output("tasklist").splitlines()]
    [prog.pop(e) for e in [0, 1, 2]]  # useless
    for task in prog:
        if task[0] == process:
            n = n + 1
    if n > 0:
        return True
    else:
        return False

for subdir, dirs, files in os.walk(AppsNewDir):
    for file in files:
        if ".apk" in file:
            print file
            command = "adb install -r " + AppsNewDir + "\\" + file
            #os.system(command)
            proc = subprocess.Popen(command, shell=True,
                         stdin=None, stdout=None, stderr=None, close_fds=True)
            counter += 1

            if counter == 5:
                while is_process_running("cmd.exe"):
                    time.sleep(1)
                counter = 0

Currently it appears to be running sequentially rather than simultaneously, I may be wrong but based on what I see in console in real time it

Ryflex
  • 5,559
  • 25
  • 79
  • 148
  • In order to be on the safe side I always use `"C:\\NewApps"` or `r"C:\NewApps"` on Windows. For example, `"c:\newapps"` would be `c:` followed by a new line and `ewapps`. – Paulo Scardine Sep 27 '16 at 06:30
  • Yeah that was a mistake my side, it wasn't causing any issue but I've modified the above. – Ryflex Sep 27 '16 at 10:36

0 Answers0