How to run a Matlab script/m-file through batch file on system startup? - matlab

I've got a Matlab script which needs to be run every time the system reboots. I've got the Matlab setup on a system server. The system reboots every week (On Sunday, but not specific to any time period).
Can I run the m-file every time the system reboots?

You can run any matlab script from the terminal using the command
matlab -nodisplay myfile.m
So if you include that line in a batch script, which your system runs at startup, it should be run every time your system reboots.

Related

Why would Redgate SQL Data Compare command line execution run significantly longer than GUI execution

I'm running a project from the command line using a command like this:
sqldatacompare /Project:"C:\temp\Validation.sdc"
This ran for days (more than 4 days) without finishing. However if I open the same project in the GUI it finishes in an hour or so. Is the GUI using some additional options that I should enable at the command-line?
I'm running 13.8.0.12703.

Run a bat file when a specific application is opened in Windows XP

I want to know how can we run a bat file when a specific application is opened?
Eg: I would like to run a bat file whenever mspaint is opened.
I have successfully performed this in Windows 7 and Windows 10 using Task Scheduler. But the task scheduler available in Win Xp is very basic.
You could use another batch file that runs on startup of windows. use while loop with an appropriate sleep to detect when Paint.exe runs.
then you could write more commands to do anything you want. For example, as you said, you could run another batch file...
I found this solution by an investigation of these topics:
Syntax for a single-line Bash infinite while loop
How to check if a process is running via a batch script
Batch program to to check if process exists

How do I quit/close a lot of MATLAB instances after the execution of a script is finished through Batch script?

I execute a matlab script which call other Batch scripts and generate with that other matlab instances (as if i opened matlab multiple times) at the same time at the end stay a lot of opened matlab windows , how can i to kill all matlab.exe instances running on my system. after finishing the execution of my main script ?
You can use quit or exit to terminate SAME matlab instance. https://www.mathworks.com/help/matlab/ref/quit.html
So, put these codewords at the end of the scripts so matlab instances close after scripts finish.
You cannot use matlab to terminate other running processes on your system. But you can run an external script - say some batch command that kills all matlab.exe instances running on your system. You do that by doing system('scriptName') in matlab, where scriptName is whatever you named this external bat script that kills the process.
To kill the process isn't a matlab question. One-liner solution can be found here:
https://superuser.com/questions/564878/killing-all-instance-of-a-specific-program-from-the-command-line
Solution for that script together with MATLAB code can be even found as a matlab question, coincidentally with exactly the "kill all instances" question:
https://www.mathworks.com/matlabcentral/answers/472-can-i-run-a-bat-file-with-matlab

Matlab fails to run a script when scheduled with Task Scheduler

I am trying to start Matlab and run a script scheduled at a specific time using the windows Task Scheduler.
If I use a scheduled task I can see Matlab starting, but this last fails to load the script and returns me the error below
??? Unexpected Matlab operator.
Do you know what it is and why?
I am using the following syntax
c:\app\matlab\bin\matlab.exe -r c:\MyURL\ScriptFile.m
If I load the script manually and run it it tells me that the file is not in the path so give ms a choice between
Change Current Directory
Add Folder to the Path
Either choices are fine and the script runs fine.
Matlab is starting in its main directory and -r requires your function to be in quotation marks, thats why you get the error.
And you need to change to your workspace first, the syntax is as follows:
matlab -sd pathToYourWorkspace -r "function(parameters)"
Maybe you also want to avoid the complete loading of the whole Matlab working environment, so add at the end:
-nodesktop -nosplash
If you run your task sheduled, are you doing it multiple times? Are you aware that every function call like above opens a new instance of Matlab? This question may be helpful then.
From the comments: of course you could just use the command run to call a script wherever it is.
"run('c:\MyURL\ScriptFile.m')" is an example for "functionName(YourArgs)"
as run is a function and the string 'c:\MyURL\ScriptFile.m' its argument. In this case it is usually not necessary to change the workspace before.

simple command prompt one line into exe

I have a perl script that I run from the command prompt: 3 times a day, the problem is now I need to run it every two hours. Im not going to be on an episode of lost so I need some help. Here is the command:
Perl C:/test/scripts/edi.pl
Does anyone know how this above one line command can be made into an executable (.exe) file so I can use the task scheduler to run?
If there is another way to do this with the task scheduler to run once every two hours every day then I could do that as well.
Thanks for your time.
Can you not simply create a batch file that runs the script, and set that batch file to run every two hours? I know from a quick test there that I can schedule a batch file to run from Task Scheduler on Windows XP at least.
You can actually use the task scheduler to run that exact command without a batch.
The task scheduler should allow you to pass some arguments to the script without a problem (I have done this on a few Windows servers in order to have them run PHP scripts)