1,105,450 Community Members

Executing DOS batch files in Python

Member Avatar
Prachu
Newbie Poster
5 posts since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
BearofNH
Posting Whiz
354 posts since May 2007
Reputation Points: 104 [?]
Q&As Helped to Solve: 63 [?]
Skill Endorsements: 4 [?]
 
0
 

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.

Member Avatar
Prachu
Newbie Poster
5 posts since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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...

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 

Try something like this ...

program = "C:\\Python25\\Test\\LH-Sitekit\\sitekit\\engine\\install-nt.bat"
# supply the proper input values as strings
input1 = 'x'
input2 = 'x'
input3 = 'z'

import subprocess
subprocess.call([program, input1, input2, input3])

Sorry, line one comes out a little goofy. Toggle to plain text to see the correct line.

Member Avatar
Prachu
Newbie Poster
5 posts since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi..

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

Member Avatar
mohangbits
Newbie Poster
1 post since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi..

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

Hi .. ! U can do it like this

import os

os.system('install-nt.bat %s %s %s < %s'%(input1,input2,input3,'C:\command.txt'))

Hope this works [:P]

- Mohan :) :P

Member Avatar
Prachu
Newbie Poster
5 posts since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks a lot! It works! :)

Question Answered as of 4 Years Ago by vegaseat, BearofNH and mohangbits
Member Avatar
changtraidoc
Newbie Poster
1 post since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

input1 input2 input 3, what are those???

someone can expland to me:D

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article