Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Controlling matlab from VB.NET

Posted on 2004-04-01
4
Medium Priority
?
992 Views
Last Modified: 2007-12-19
Hi,

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)
        Thread.Sleep(20000)

       SendKeys.SendWait("m-file")
        SendKeys.SendWait("{ENTER}")
__________________________________________________________________________

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.
0
Comment
Question by:chspit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10732313
0
 
LVL 14

Expert Comment

by:ptakja
ID: 10732932
Instead of using the Shell command, check out the Process component.

To start MatLAB, for example, you could enter:

Process.Start("C:\MATLAB6p5\bin\win32\matlab.exe")

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:  http://www.mathworks.com/support/solutions/data/36616.html

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.

0
 

Author Comment

by:chspit
ID: 10734659

Mikal613,

The link you gave explains how to wait for a program to end before continuing with the
processing.
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).
0
 
LVL 14

Accepted Solution

by:
ptakja earned 375 total points
ID: 10736598
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).
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question