I'm working in windows, writing a python program which runs various programs through command line and pipes the outputs of one into the next program. All the programs accept all instructions in one line then run. I've been using the os.system command to run these. One program though does not work in this manner - it prompts the user for the input file name/location then once it receives this, prompts with the name and desired location of output, etc., until it receives all the information necessary to run. Just providing all the necessary information separated by newlines has not been working and I was hoping that perhaps someone might have suggestions as to how I can make this happen?
Essentially I start this particular program by typing its name to command line. The program clears the screen and prompts me for the input file. Once it has received that it requests various other pieces of information, asks me to check a menu of settings and change things, (by pressing "I" to change one setting for example) and so on. Kind of like a continuous question and answer til it has all the information it requires. Here is some of my code as it was yesterday - it might help explain what I am trying to do:
dnamlLocation = "..\\..\\PHYLIP\\dnaml"
dnamlInput = "..\\..\\OutputFiles\\alignedWith0.1SeqError.phy"
dnamlOutput = "..\\..\\OutputFiles\\dnamlOutput.phy"
dnamlOutputTree = "..\\..\\OutputFiles\\dnamlOutputTree.phy"
outputFileResponse = "F" # produce new output file with name and location as specified
changeToSequential = "I"
confirmSettings = "Y"
outputTreeFileResponse = "F" # produce new output file with name and location as specified
cmd = dnamlLocation + ' | ' + dnamlInput + ' | ' + outputFileResponse + ' | ' + dnamlOutput + ' | ' + changeToSequential + ' | ' + confirmSettings + ' | ' + outputTreeFileResponse + ' | ' + dnamlOutputTree
Since then I've been trying a pipeine approach but I don't think that I've been going about it the right way. I think I've got the usage wrong. I tried something like "os.system("myprogram.exe < myinput.txt")" yesterday but I couldn't get it to work.
Any ideas why that might be? Any advice in general would be great.
'F' is not recognized as an internal or external command,
operable program or batch file.
Basically it throws an error the second it reaches the outputFileResponse variable (which is equal to 'F').
If possible I would like to avoid putting dnaml in the path because I have a number of programs which work a similar way and this code should be usable by others in a biological setting - adding things to path could be less straight-forward for them.
Thank you so much for your reply. Subprocess did it in the end for me. I hadn't heard of ScriPy though, definitely want to look into that a little more.
One more question if you don't mind, how are you supposed to gracefully close the subprocess once you're done? I tried "subprocess.terminate()" and suddenly my pc got blue screened each time I tried to run my code =P I've never seen anything like it.
Thanks so much for all your help! You guys are lifesavers =)