Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6146571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:58:07+00:00 2026-05-23T18:58:07+00:00

When starting the external program (let’s call it EX for brevity) from within Matlab

  • 0

When starting the external program (let’s call it “EX” for brevity) from within Matlab I can either do it like this

[status, result] = system('EX.exe');

which blocks until EX returns, or like this

[status, result] = system('start EX.exe');

which returns to Matlab immediately but can’t fetch EX’s return code.

It would be nice to still have EX’s return code available in Matlab once it is done. This would be the easiest way for the calling Matlab script to notice any problems EX might run into. On the other hand, I would like Matlab to do other stuff while EX is running, e.g. displaying information on progress. So, the call needs to be non-blocking.

I tried to work around this obvious conflict by starting EX as described in the first example above. To be able to run some other code (displaying progress information) while EX is busy, I put this code into a function and called that by using a timer with a small StartDelay.

Unfortunately this does not provide real multithreading (something that Matlab seems to be incapable of without Parallel Computing Toolbox), i.e. if the code in the timer callback runs longer than EX, execution again blocks until the timer callback returns. Even worse: Since I don’t know how long EX will run, the timer callback must run endlessly until it is either stopped or passed some flag that tells it to stop. I tried with global variables or even storing this flag in application data like this:

setappdata(0, 'running', 1);

tim = timer(...
    'StartDelay', 2, ...
    'TimerFcn',   'while getappdata(0, ''running''), fprintf(''timer running ...\n''); pause(1); end' ...
);

fprintf('Starting timer.\n');
start(tim);

fprintf('Calling external program ...\n');
[s,r] = system('EX.exe');
fprintf('External program returned %d.\n', s); % <-- This is never reached.

setappdata(0, 'running', 0);

fprintf('Stopping timer.\n');
stop(tim);
delete(tim);

The code following the call to system() never seems to be executed and the timer callback runs forever … Is there any other way I can get this to work or is it really either system’s return value OR non-blocking call?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:58:07+00:00Added an answer on May 23, 2026 at 6:58 pm

    I’m not sure MATLAB has native/built-in support for spawning a process. You can use Java from MATLAB to implement it, though.

    For instance,

    >> runtime = java.lang.Runtime.getRuntime();
    >> process = runtime.exec('program arg1 arg2');
    >> ...
    >>
    >>   % when you want to collect results.
    >> process.waitFor(); % block until program returns.
    >> process.exitValue(); % fetch process return code.
    >>
    >>   % or, if you need to abandon the work,
    >> process.destroy(); % violently kill process
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting an external process in my Java program (on Linux) and I
This is really starting to piss me off. I feel like I have tried
Starting with 2005, VS started this behavior of when starting debugging session it spawns
Starting from ASP.NET MVC Preview 3, HTML.Button ( and other related HTML controls) are
Starting a new project and would like to use one of the MVC framworks.
Starting with the error: Error 81 The OutputPath property is not set for this
Starting with the following LINQ query: from a in things where a.Id == b.Id
Suppose I have a program A. I run it, and performs some operation starting
This is really strange and I can't seem to figure out why it won't
I'm just starting to learn the C programming language. I've written this simple piece

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.