0

From a script in Matlab, I need to run an external command. Normally this is done with system, but script execution blocks until the command completes. Is there a way to execute a command from a script without blocking execution?

EDIT: OS is Windows Server.

3 Answers 3

2

On windows you need to use start

system('start notepad.exe');
Sign up to request clarification or add additional context in comments.

Comments

2

This may be overkill, but if you have the full install of matlab, you can use the Parallel Computing toolbox to run the command in a separate thread. It's actually pretty easy to do, the basic syntax would be:

obj = createJob();
set( obj, 'FileDependencies', {<list .m files used here>, 'ExampleFileFunc.m'});
task = createTask(obj, @ExampleFileFunc, 1, {4});

submit(obj);                   

waitForState(task,'finished');
varargout = get(task,'OutputArguments');

The {4} is the number of outputs from ExampleFileFunc.

Comments

1

You can use bang (!) and then the command, for instance

 !vi

And to let it run without blocking execution it would be

 !vi &

The program will show up on a separate screen and you get back to the Command Window so you can continue running MATLAB language statements. It does the same thing for an script so I guess this is what you want to use.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.