필터 지우기
필터 지우기

Send PuTTY Command Through Matlab Script

조회 수: 14 (최근 30일)
Sam
Sam 2013년 7월 18일
Hi, all,
I am attempting to open the terminal emulator PuTTY and send a command through the PuTTY terminal using a Matlab script. I am able to open PuTTY and even open a predefined, saved serial session in Matlab (called "serialsessoin" in script below), but I'm uncertain how to go about writing Matlab code to send a command through PuTTY once the terminal emulator is open. Ultimately, I'd like to open the PuTTY terminal window and send a single "enter" key through the terminal.
In my script below, a1 is a binary "1" (aka command unsuccessfully sent) or "0" (aka command successfully sent), and b1 is the output of the command. I've attempted to use Matlab's fprintf function to send PuTTY a carriage return through Matlab, but I realize that my fprintf function isn't explicitly directed to the PuTTY terminal. And while I recognize my fprintf function isn't used quite right to begin with, I run into a problem even before the fprintf function: as long as the PuTTY terminal window is open, the first line of code is never passed, so the fprintf function is never reached until I manually close the PuTTY terminal window!
So, in short, my question is this: how can I pass a command through the PuTTY terminal using a Matlab script?
Any ideas would be great. Thanks!
Sam
**************rough code below****************
[a1 b1] = system('"C:\Program Files (x86)\PuTTY\putty.exe" -load "serialsession"');
fprintf(eval('\n'))

채택된 답변

Muthu Annamalai
Muthu Annamalai 2013년 7월 18일
AFAIK this is not currently possible in MATLAB, i.e. to have a live terminal session - you need pipes and MATLAB doesn't offer them. You probably want to write this in C/C++ and use a MEX file to access it from MATLAB.
MATLAB can fire off a shell program pretty well, and put it in background or wait for it etc, but it can't do pipes as of today.
Your best chance is to redesign your task to do pipe/I/O stuff in lower level C/C++ like language and fireoff this program from MATLAB with appropriate parameters.
  댓글 수: 2
Sam
Sam 2013년 7월 19일
Thanks, Muthu, for your insight. While I think that I understand your advice (at least on a conceptual level), I have very little programming experience writing in C/C++ and absolutely no experience dealing with "pipes". (Ha ha, I just tried to write a couple simple C++ scripts and struggled immensely.) At least I can stop trying to use Matlab to accomplish something that simply may not be possible! Thank you for the help!
Muthu Annamalai
Muthu Annamalai 2013년 7월 19일
It could be possible with Java, from MATLAB but I haven't tried.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by