please help the newbie-controling an external program via python
hey guys n girls, im using python 3.1.2
i am currently creating a process to:
1) check a directory does not exist,
2) check for illegal char's from a list i have made,
3) pass it to a program,-program creates directory,
4) and passes a value back to python
5) and loop until told otherwise
i have got to the point where i have to pass the string / text to a program and this is where i have hit a brick wall?
what and how should i pass the text across (i would prefer to use something like "cmd")
i can get cmd to open a program from within my python script but cannot get it to pass any text or strings across to the program.
any help would be fantastic or any suggestions on what module or function to use
string=input('enter new directory name: ')
i need to pass the input from the user to a external program (a text based program) i haven't posted my whole code as it all works smoothly apart from me being a newbie and not being able to work this problem out
thanks again
danholding
Junior Poster in Training
56 posts since Aug 2010
Reputation Points: 15
Solved Threads: 1
Why you do not do everything in Python? What external program does except creating the directory?
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
the external program then sets conditions for the folder and puts databases in to it and creates log files?
i just need the command for typing a string or text in to a external program as i can get it to open the program but not to type anything?
danholding
Junior Poster in Training
56 posts since Aug 2010
Reputation Points: 15
Solved Threads: 1
the external program then sets conditions for the folder and puts databases in to it and creates log files?
i just need the command for typing a string or text in to a external program as i can get it to open the program but not to type anything?
You must tell us how the external program usually receives these strings: from command line options ? from an interactive session in a terminal ? from a GUI ?, from a socket ?
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
well atm while i am editing this file i am using runasdate.exe from an interactive session in terminal i can get it to open runasdate via a batch file but it wont pass the text / string though 2 runasdate
danholding
Junior Poster in Training
56 posts since Aug 2010
Reputation Points: 15
Solved Threads: 1
well atm while i am editing this file i am using runasdate.exe from an interactive session in terminal i can get it to open runasdate via a batch file but it wont pass the text / string though 2 runasdate
Try to run it with this Command class http://www.daniweb.com/code/snippet257449.html
com = Command('RunAsDate.exe 14\02\2005 "c:\temp\myprogram.exe" param1 param2 "').run()
if com.failed:
print com.error
print com.output
(replace the command line by your command line). Otherwise, try to use subprocess.Popen directly.
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
Take a look at pexpect in addition to subprocess.
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
i have tried using pexpect but it is not compatible with python 3.1 without a good hours of correcting errors and at the current point in time i do not have the time to do that.
danholding
Junior Poster in Training
56 posts since Aug 2010
Reputation Points: 15
Solved Threads: 1
i have tried using pexpect but it is not compatible with python 3.1 without a good hours of correcting errors and at the current point in time i do not have the time to do that.
Did you obtain results with the subprocess module ?
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691