how can i run m file in a active sesion from command promt?

3 views (last 30 days)
I'm wrting an algorithm for software by compiling my code using deploytool. the interaction with the software is with text files:
my_algorithm.exe in.txt out.txt
for debug i want to run the code from mathlab using breakpoints and the environment. i know i can run it using:
<matlabroot>\bin\matlab.exe -r my_algorithm.m
however, it will open a new sesion every time which will takes a lot of time and wont remeber my breakpoint.
is there a way to run the function without opening a new sesion every time.

Accepted Answer

Shachar
Shachar on 13 Jan 2015
A brute force solution:
using the software cmdow i meneged to do this in 4 steps: 1. download cmdow from the link: http://www.commandline.co.uk/cmdow/ 2. write a robot matlab code that types like a real person:
function keyboard_robot(varargin)
%types the input as if a user typed it and then press enter
%keyboard_robot(command)
%import
import java.awt.*;
import java.awt.event.*;
rob = Robot;
%extract ascii code from string
mytext = double(varargin{1});
%init the numpad keys
keys = arrayfun(@(d)eval(sprintf('KeyEvent.VK_NUMPAD%d',d)),0:9);
%loop over all characters
for textInd = 1:length(mytext)
%enter the key using ALT + <ascii code>
%hold ALT
rob.keyPress(KeyEvent.VK_ALT);
%loop on digits of each ascii code
for iDig = 3:-1:1
%take the current digit
dig = floor(mod(mytext(textInd), 10^iDig) / 10^(iDig - 1));
%press the digit
rob.keyPress(keys(dig + 1))
pause(0.02)
rob.keyRelease(keys(dig + 1))
end
%release ALT
rob.keyRelease(KeyEvent.VK_ALT);
end
%press Enter
rob.keyPress(KeyEvent.VK_ENTER);
rob.keyRelease(KeyEvent.VK_ENTER);
end
3. compile the function into EXE
4. write a bach file to use the two EXEs:
for /f "tokens=1,9" %%a in ('cmdow /t') do (
if /i "%%b"=="MATLAB" cmdow %%a /ACT
)
keyboard_robot %1
just start the back with parameter of the command: c:\folder> run_matlab_from_cmd.bat my_function(myParameters)
IMPORTENT: i couldn't find a way to move to command window so befor running make shure that the command window is in focus!
enjoy.

More Answers (0)

Categories

Find more on External Language Interfaces in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!