Trouble when calling a bat file

i have a python script that running perfectly using the anaconda env.
i created a bat file that call to my python script, and when i double clicking the bat file it running perfectly also.
also when i call to the bat file from cmd it works fine.
BUT, when i call to the bat file from matlab2021a usung the system() it gives this error message:
"'cmd' is not recognized as an internal or external command,
operable program or batch file."
and also:
"RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning) "
By the way, i alread add my PATH to matlab.
The biggest thing is that last night i could have run the bat file from matlab, woke up this morning and got that issue before change nothing:(
Hope for answers:) Thanks

11 commentaires

Show how you make up the batch file path and pass it to system(), for example
batFullFilePath 'C:\my batch.bat'
dataFullFileName = 'C:\myMovie.mp4'
commandLine = ['"' batFullFilePath '" "' dataFullFileName '"'];
system(commandLine);
Kfir Weissman
Kfir Weissman le 1 Mar 2022
i call "system(myBat.bat)"
Kfir Weissman
Kfir Weissman le 1 Mar 2022
yesterday it work
Kfir Weissman
Kfir Weissman le 1 Mar 2022
now it gives the error i mentioned
Walter Roberson
Walter Roberson le 1 Mar 2022
If it literally says "cmd" then you are running on MS Windows in a version before Windows XP.
... Mind you at the moment I could not swear that Windows 11 still has cmd.exe but I would think it highly likely it does.
Kfir Weissman
Kfir Weissman le 1 Mar 2022
thanks for the answers, i gotta mention that i can run everything in matlab using system(), except this batch file.
Benjamin Thompson
Benjamin Thompson le 1 Mar 2022
I have Windows 10 and this works for me:
>> !cmd
Microsoft Windows [Version 10.0.19042.1526]
(c) Microsoft Corporation. All rights reserved.
C:\Users\ThompsonBC\Documents\MATLAB>exit
exit
If you echo the PATH in MATLAB the location of cmd.exe on your system needs to be included:
>> !echo %PATH%
C:\Program Files\MATLAB\R2021b\bin\win64;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2021b\runtime\win64;C:\Program Files\MATLAB\R2021b\bin;
>>
Kfir Weissman
Kfir Weissman le 1 Mar 2022
when i run "!cmd" it gives :
'cmd' is not recognized as an internal or external command,
operable program or batch file.
Kfir Weissman
Kfir Weissman le 1 Mar 2022
how can i fix this dude?
Which operating system are you using? Which MATLAB release are you using?
If you are using Windows, then check inside C:\Windows\System32 to see if cmd.exe is there.
What shows up in MATLAB if you ask
getenv('PATH')
Kfir Weissman
Kfir Weissman le 1 Mar 2022
Modifié(e) : Kfir Weissman le 1 Mar 2022
Guys i solve the problem, I just restart matlab and its work..

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 1 Mar 2022

0 votes

Actually I don't think this will work (what you say you are using):
system(myBat.bat)
You either have to pass in a variable, or pass in your batch filename enclosed in single or double quotes:
system("myBat.bat")

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by