Hello everybody!
I have a problem with executing a script in Task Scheduler. A script needs to execute itself in the background(daily). I found several tutorials but it just doesn't seem to work. I can't configure it right. Tried this...
It runs Matlab, I've tried, but I also want it to open a script and run it. Something to do with -r as in the link above. Afterwards it would be great if it could exit the program.
Are there any other solutions? Since MatLab will always stay open, can I just specify time when it should run a particular script? I've tried TimerFcn, but as I understand it won't run scripts? Or does it?
Thank you!
I use Windows 7.

 採用された回答

Jan
Jan 2011 年 12 月 19 日

2 投票

You can use this call to start the function "YourFcn", wait for 10 seconds and close Matlab afterwards:
matlab -r "YourFcn; pause(10); exit"
This call can be used in Window's Task Schedular.
Another idea would be to add the exit to the function.
The TimerFcn can run scripts. Simply insert the script name as String as the TimerFcn. But I bet, Matlab will not stay open all the time. The Task Schedular of the operating system is more reliable.

3 件のコメント

raym
raym 2017 年 5 月 6 日
taskname = 'SuperColocRescue';
runfile = ['C:\Program Files\MATLAB\R2016a\bin\matlab.exe -nosplash -nodesktop -minimize -r CMDEntryExitSuperColoc(''D:\QMDownload\SuperColocParaImport1.txt'')'];
frequency = 'ONCE';
starttime = '21:45';
system(['schtasks /create /tn "',taskname,'" /tr "',runfile,'" /sc ',frequency,' /st ',starttime,' /f']);
%%%%%%%%%%
The result is that input string argument has lost the ', no longer a string.
%%%%%%%%%%
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
CMDEntryExitSuperColoc(D:\QMDownload\SuperColocParaImport1.txt)
|
Error: Unexpected MATLAB operator.
%%%%%%%%%%
Image Analyst
Image Analyst 2017 年 5 月 6 日
It worked for me
runfile =
C:\Program Files\MATLAB\R2016a\bin\matlab.exe -nosplash -nodesktop -minimize -r CMDEntryExitSuperColoc('D:\QMDownload\SuperColocParaImport1.txt')
SUCCESS: The scheduled task "SuperColocRescue" has successfully been created.
raym
raym 2017 年 5 月 6 日
Yes, I'm not saying the schedules task could not be created. However, when it is executed, the ' will lose.

サインインしてコメントする。

その他の回答 (2 件)

Slobodan Djordjevi?
Slobodan Djordjevi? 2011 年 12 月 19 日

0 投票

Thanks for the info.
How do I create Task Scheduler, so a file would run itself?
I could only get it to open an .m file.
MatLab is in C:\Program Files\MATLAB\R2011a\bin\matlab.exe and the script is in C:\Users\Slobodan\Documents\MATLAB\Primeri called opozarjanje_maj_kol.m.
C:\Program Files\MATLAB\R2011a\bin\matlab.exe -r opozarjanje_maj_kol [would not work in Edit Action]
Could you help me out?

3 件のコメント

Daniel Shub
Daniel Shub 2011 年 12 月 19 日
This is really not a MATLAB question, but I think if you create a .bat file with that line and then include the name and path of the .bat file in the action, you would be okay.
Jan
Jan 2011 年 12 月 19 日
I've used "matlab" instead of including the path on purpose. The path of your Matlab executable contains a space. You can try to include it in double quotes.
Or add the path to the Matlab function in the "Start in" field.
Jan
Jan 2011 年 12 月 20 日
Accepting a question means, that the problem is solved by this question.

サインインしてコメントする。

Slobodan Djordjevi?
Slobodan Djordjevi? 2011 年 12 月 20 日

0 投票

Thank you all!
I've done it like Jan Simon suggested and it works great!
Thank you Daniel, I'll look into that too to see any benifits.

1 件のコメント

Jan
Jan 2011 年 12 月 20 日
Please accept the answer, which solves the problem, and add comments in the comment section and not as additional answer. Thanks.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2011 年 12 月 19 日

コメント済み:

2017 年 5 月 6 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by