MATLAB: Communicating with an external program

external programjava robotlinuxsystem

I am using a program called stp found here: http://scedc.caltech.edu/research-tools/downloads.html
Essentially what I am trying to do is within my matlab script have it use stp and request downloads of data that I have outlined in the script. The issue is from what I have found so far, system() doesn't allow me to continually communicate with the program (as in, send it additional commands).
stp cannot be called with any additional options or already telling it what file you want it to send you, you have to wait for it to connect first, and then send a request. My biggest problem is that once I send the command to run stp matlab sits and waits for it, but it's really waiting for another input itself. So when I run it I will get:
>> stprun %example name of script that at one point has a system('stp') command
STP: connected to caltech... etc, a lot of other stuff. basically what I would see if I ran this from any terminal.
STP>
And that's basically where it stops and waits. I don't know how to give additional inputs into "STP>", which is waiting for inputs, because matlab is also waiting for a return. I have to manually type "exit" and then hit enter which will give matlab nothing back and then the script will fail. I don't really care about a return, I just want to be able to tell STP what to do, and then have the script continue. Like send keypresses to the terminal somehow, once I start STP.
If it matters any, I'm running this on Linux.

Best Answer

There is a popen() in the File Exchange that can be used in Linux and OS-X . It does not support bidirectional transfers, but if you do not need to analyze the responses then you should be okay by just redirecting the output to a file (and possibly reading the file afterwards.)
On the other hand, if it is just a matter of sending input to a command line program without needing to interact with it, then there is a much easier way: write all of the desired commands into a file, and then when you system() redirect standard input from the file.
Related Question