Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python loop in subprocess
#1
Hi All,

I was trying to use a config ini file in one of the script. Below is my config file looks like

[DEV]
APPNAME = APP1 APP2

I was trying to use this value(APPNAME) in the script one by one in the loop on subprocess, can someone help it always execute the very first one i.e APP1

Thanks
Reply
#2
Wouldn't it help to see your code?
Reply
#3
This is the piece of code where am trying to iterate the value of {{app}} from conf.ini file.

Quote:subprocess.check_call(["/bin/ansible-playbook", "tomcatPlayBook.yml", "--extra-vars", ("appName={}".format(app))])

Thanks,
Vinoth
Reply
#4
There's no iteration in there. Please, show all the relevant code - don't make us guess. You should also be using "[python]" tags for code, not "[quote]" ones.
Reply
#5
Sorry am relatively new below is code.

class Handler(FileSystemEventHandler):

    @staticmethod
    def on_any_event(event):
        if event.is_directory:
            return None

        elif event.event_type == 'created':
            print "Received created event - %s." % event.src_path
            fname = event.src_path
            filename = os.path.basename(fname)
            app = config.get(env, filename)
		for i in app
            subprocess.check_call(["/bin/ansible-playbook", "tomcatPlayBook.yml", "--extra-vars", ("appName={}".format(app))])

        elif event.event_type == 'modified':
            print "Received modified event - %s." % event.src_path
            fname = event.src_path
            filename = os.path.basename(fname)
            app = config.get(env, filename)

	    for i in app 
            subprocess.check_call(["/bin/ansible-playbook", "tomcatPlayBook.yml", "--extra-vars", ("appName={}".format(app))])

if __name__ == '__main__':
    w = Watcher()
    w.run()
Thanks,
Vinoth
Reply
#6
Does that code even run? You should be getting syntax errors due to missing colons on lines 13 and 22. You're not even using your loop variable i...
Reply
#7
Thanks for checking it out. Its a copy paste issue, yes running but not the way am trying to achieve, say if the variable resolve to something like this

app = APP1 APP2

i want to iterate twice on the sub-process. I am just learning so any help would be appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Breaking subprocess loop from parent process kapibara 3 3,862 Aug-28-2019, 11:34 PM
Last Post: kapibara
  Python Error in subprocess.py roydianton90 1 5,590 Dec-14-2018, 11:26 AM
Last Post: jeanMichelBain
  OS command via python subprocess module alinaveed786 21 10,818 Oct-23-2018, 05:40 AM
Last Post: alinaveed786
  subprocess in thread python to check reachability anna 3 3,428 Sep-05-2018, 04:01 PM
Last Post: woooee
  Using Subprocess.Popen to start another python script running in background on Window johnb546 0 13,661 Jun-01-2018, 01:57 PM
Last Post: johnb546
  proc communicate not exiting on python subprocess timeout leoonardoo 0 3,783 Sep-13-2017, 09:54 AM
Last Post: leoonardoo
  I have problem on Communication between C++ and Python using subprocess Module hlfan1234567 0 4,239 Jul-09-2017, 04:34 PM
Last Post: hlfan1234567
  trying out subprocess in python sblu23 3 4,013 Jul-05-2017, 09:18 PM
Last Post: nilamo
  Encoding issue while running Sysinternals Autorunsc via Python subprocess JChris 0 3,447 Jun-13-2017, 12:01 AM
Last Post: JChris

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020