#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10

    Question wait until a process has finished before running next one


    i have a program that deletes files from various folders on my PC.
    it then runs a ws-ftp script to copy files from an ftp site and back the files up.
    i then distribute the files to various folders on the PC and add the file details to a MySQL database before running another FTP script to upload the files to another FTP site.

    i need to check that the all the files have been downloaded before moving them around and before running my ftpout process. i have put a sample of the code below and highlighted the FTP in and FTP out sections

    Code:
    def kalin():
        # run ws_ftp scrpt.exe and the KALIN script using .bat file
        os.startfile("C:\\VDATA\\FTPScripts\\kALin.bat")
    
    
    def data():
        import os, shutil
        bst = ("C:\\VDATA\\KAL\\DATAOUT\\")
        rnc = ("C:\\VDATA\\KAL\\RNC\\")
        list = os.listdir("C:\\VDATA\\KAL\\DATAIN")
        list.remove("BAK")
        for x in list:
    	if x[-3:].lower() == "bst":
    		shutil.copy("C:\\VDATA\\KAL\\DATAIN\\" + x, bst)
    	elif x[-3:].lower() == "rnc":
    		shutil.copy("C:\\VDATA\\KAL\\DATAIN\\" + x, rnc)
    
    
    def database():
        
        #import MySQLdb module
        import MySQLdb, datetime
        #connect
        db = MySQLdb.connect(host="localhost", user="******", passwd="******", db="kal")
        #create a cursor
        cursor = db.cursor()
        
        list = os.listdir("C:\\VDATA\\KAL\\DATAIN")
        list.remove("BAK")
        for x in list:
    	cursor.execute("INSERT INTO tblkal (filename, date) VALUES (%s, %s)", (x, datetime.datetime.today()))
    
    	
    def kalout():
        # run ws_ftp scrpt.exe and the KALOUT script using .bat file
        os.startfile("C:\\VDATA\\FTPScripts\\KALOUT.bat")
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Try using os.system() instead of os.startfile(). This pauses your python script until the program is done running. Another alternative would be to ditch the ws_ftp script altogether and use python's own ftplib.

    Comments on this post

    • macca1707 disagrees
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10
    thanks a lot, os.system worked great

    i already had the ws-ftp scripts from a previous VB script used for this program as it was more reliable than my own efforts.

    thanks again

IMN logo majestic logo threadwatch logo seochat tools logo