Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5225

Re: Need Assistance on this program.

Date 2011-05-12 11:38 +0100
From Tim Golden <mail@timgolden.me.uk>
Subject Re: Need Assistance on this program.
References <BANLkTi=HJ6Ve2t9=EP1sGfMbR6ZoLtgy7g@mail.gmail.com> <sa0hb901dor.fsf@gmail.com> <BANLkTi=PW6xCTQ9ReYFdtgO+rnU2tAW_Ww@mail.gmail.com> <4DCBB18B.5050309@timgolden.me.uk> <BANLkTimX-tDpveXUqdGy2vBCWuqQ0VPabA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1459.1305196686.9059.python-list@python.org> (permalink)

Show all headers | View raw


On 12/05/2011 11:29, vijay swaminathan wrote:

<... snippet from code ...>
   print 'Invoking Command Promptt..............'
         #subprocess.call(["start", "/DC:\\PerfLocal_PAL", 
"scripts_to_execute.bat"], shell=True)
         subprocess.call(["start", "C:\\windows\\system32\\cmd.exe"], 
shell = True)
         self.status()
</snippet>

If you want to use start, use start /wait.

But you don't have to:

<code>
import threading
import time
import subprocess

def run_command (command):
   #
   # .call is shorthand for: start process and wait
   # CREATE_NEW_CONSOLE prevents it from getting messed
   #  up with the Python console
   #
   subprocess.call (
     [command],
     creationflags=subprocess.CREATE_NEW_CONSOLE
   )

t = threading.Thread (target=run_command, args=("cmd.exe",))
t.start ()

while t.is_alive ():
   print "alive"
   time.sleep (0.5)

print "Thread is dead"

</code>

TJG

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Need Assistance on this program. Tim Golden <mail@timgolden.me.uk> - 2011-05-12 11:38 +0100

csiph-web