Using MATLAB Script To Run remote Linux Program via Telnet

I have a C program on Linux Fedora 14, and now I am trying to remotely running it from a different PC using MATLAB via telnet. But right now all I can do is calling putty from matlab to access Linux terminal, and run the program through this remote terminal. But it is useless for me because I can't automate the MATLAB script to call the program repeatedly.
To illustrate my situation. Say I have a program Hello as following:
void main (int argc, char* argv){
if(argc > 0){
printf("Hello %s \n", argv);
printf("result is %d", argc++);
}
return;
}
I want to have a MATLAB script that can run this program from a remote PC and input a name and read the result multiple times. But now all I have is calling
system('C:\Putty\putty.exe <ip_address> -username -password')
from matlab and get the remote terminal on Linux, then manually run
./hello name.
How can I run the whole program from matlab directly through telnet? And get the result?
Thanks.

 Accepted Answer

You might want to try uing "plink" rather than PuTTY. It's part of the PuTTY suite, so you likely have it already since you've installed PuTTY.
Section 7.3 is pretty close to what you are trying to do.
As for getting the result, the program can output to the terminal and you can use
[status,result] = system(<system command here>)
to get it. Or, if you have a common filesystem between the two systems, you could output it there and then retrieve it.

5 Comments

Thanks for the timely response. The problem I have right now is that once system(<system command>) is entered, the console will pop up and no more script can be run until the console is manually closed, so I still can't automate the program to run automatically.
You should be able to put in something like the following, replacing the username, password and remote_hostname with your desired values:
[status,result] = system('plink -telnet -l username -pw password remote_hostname ./hello name')
and the result of the run will be in the variable "result"
It's probably worthwhile to try it outside MATLAB first, then put the result inside the system command, as things can get tricky to troubleshoot through too many layers of indirection.
Thank you so much, it is working now. But somehow I have to replace -telnet to -ssh, otherwise it will show up
plink: the -pw option can only be used with the SSH protocol
Is this normal?
Well, if there is a specific error condition for it, I'd guess so. :)
I haven't used telnet in a while -- does it challenge you for a password? In general, I'd say ssh is probably the more portable and maintainable choice, anyway -- telnet and rsh are still useful tools, but the world has largely moved to ssh for any number of reasons (secure, traceable, configurable, standard, debuggable, etc)

Sign in to comment.

Asked:

Sy
on 14 Feb 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!