1.11M Members

Executing DOS batch files in Python

 
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

 
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.

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

 
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.

 
0
 

Hi..

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

 
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

 
0
 

Thanks a lot! It works! :)

Question Answered as of 5 Years Ago by vegaseat, BearofNH and mohangbits
 
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