Executing DOS batch files in Python

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2008
Posts: 5
Reputation: Prachu is an unknown quantity at this point 
Solved Threads: 0
Prachu Prachu is offline Offline
Newbie Poster

Executing DOS batch files in Python

 
0
  #1
Apr 17th, 2008
Hi all..

I am new to Python and badly need help...I am trying to run a DOS batch file from Python..I have given the inputs also..It runs half and then exits at the point of time when I need to give answer to whether I need to replace two files or not...when that interrupt comes up the batch file just closes and no error is logged...how do I get to give that user input in the middle...is it possible???Is there any way that the python would prompt us to enter the values???
Thanks in advance
Prachu
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 311
Reputation: BearofNH is on a distinguished road 
Solved Threads: 40
BearofNH's Avatar
BearofNH BearofNH is offline Offline
Posting Whiz

Re: Executing DOS batch files in Python

 
0
  #2
Apr 17th, 2008
Have you looked at popen2? It's documented in the Python run-time library manual and I'm sure google will show lots of examples.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 5
Reputation: Prachu is an unknown quantity at this point 
Solved Threads: 0
Prachu Prachu is offline Offline
Newbie Poster

Re: Executing DOS batch files in Python

 
0
  #3
Apr 17th, 2008
i am sorry but I am not able to execute that command as a sub-process as it says in the library reference...i have been using the following code :
os.system('C:\\Python25\\Test\\LH-Sitekit\\sitekit\\engine\\install-nt.bat %s,%s,%s'%(input1,input2,input3))
where the 3 inputs are defined previously...

Please could u let me know how to use popen2() with this cmd...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Executing DOS batch files in Python

 
0
  #4
Apr 17th, 2008
Try something like this ...
  1. program = "C:\\Python25\\Test\\LH-Sitekit\\sitekit\\engine\\install-nt.bat"
  2. # supply the proper input values as strings
  3. input1 = 'x'
  4. input2 = 'x'
  5. input3 = 'z'
  6.  
  7. import subprocess
  8. subprocess.call([program, input1, input2, input3])
Sorry, line one comes out a little goofy. Toggle to plain text to see the correct line.
Last edited by vegaseat; Apr 17th, 2008 at 2:04 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 5
Reputation: Prachu is an unknown quantity at this point 
Solved Threads: 0
Prachu Prachu is offline Offline
Newbie Poster

Re: Executing DOS batch files in Python

 
0
  #5
Apr 18th, 2008
Hi..

i tried this...its behaving in the same way as the os.system did..
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1
Reputation: mohangbits is an unknown quantity at this point 
Solved Threads: 1
mohangbits's Avatar
mohangbits mohangbits is offline Offline
Newbie Poster

Re: Executing DOS batch files in Python

 
0
  #6
May 2nd, 2008
Originally Posted by Prachu View Post
Hi..

i tried this...its behaving in the same way as the os.system did..

Hi .. ! U can do it like this
  1. import os
  2.  
  3. os.system('install-nt.bat %s %s %s < %s'%(input1,input2,input3,'C:\command.txt'))

Hope this works []

- Mohan
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 5
Reputation: Prachu is an unknown quantity at this point 
Solved Threads: 0
Prachu Prachu is offline Offline
Newbie Poster

Re: Executing DOS batch files in Python

 
0
  #7
May 2nd, 2008
Thanks a lot! It works!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC