Controlling matlab from VB.NET


I want to start Matlab, then run an m-file automatically.
Below is what I've done so farin VB.NET.

Shell("C:\MATLAB6p5\bin\win32\matlab.exe", AppWinStyle.MaximizedFocus)


I had to use 'sleep' to wait for Matlab to load completely before sending keys, otherwise nothing will happen.

The question is: is there a command instead of 'sleep' that knows when the application has loaded and is ready to receive keystrokes?
Also, I want matlab to quit automatically after the m-file has been run. How can I do that?

Thanks in advance for your help.
Who is Participating?
In that case just execute the Process.Start method as shown above and then call the Process.WaitForInputIdle method.  When that method returns, MatLAB should be up and running waiting for user input.  At that point you could then execute the SendKeys function(s).
Instead of using the Shell command, check out the Process component.

To start MatLAB, for example, you could enter:


I am not a MatLAB person, but I believe you can pass the m-file to Matlab on the command line.  Check out this link at MathWorks website.  It shows the syntax to do this:

Once you execute the Process.Start method, you could call the Process.WaitForInputIdle method to wait for MatLAB to get into a state where it is waiting for operator input.

Finally, call Process.Kill to stop MatLAB.

Check into the Process component in the .NET Framework.  This component gives you alot of remote control of a process from your application.

chspitAuthor Commented:


The link you gave explains how to wait for a program to end before continuing with the
However, what I wanted was a command that does not allow the SendKeys command to be executed before an application loads entirely (i.e. when an application, such as matlab, is ready to receive keystrokes after it has been instantiated).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.