Is it possible to programmatically check whether MATLAB has been started with the "-sd" option?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andre Zeug
el 17 de Sept. de 2022
Comentada: Andre Zeug
el 20 de Sept. de 2022
I have a program that needs to behave differently depending on whether MATLAB was started with the "-sd" option (sets initial working folder) or not. However, I cannot determine a way to programmatically check this.
4 comentarios
dpb
el 18 de Sept. de 2022
TMW hasn't provided a link to the command line -- I see a couple alternatives...(I've not tried either, just possible approaches that come to mind at the moment).
- Use a batch file containing the startup command and have it set an environment variable that startup.m can check, or
- Write a mex command that returns the command line and use the -r option to dispatch it. I don't know that this will work or not...
Respuesta aceptada
Jan
el 18 de Sept. de 2022
PID = feature('getpid');
[status, out] = system(sprintf('ps -p %d -o args', PID))
Parsing the char vector out is not trival: E.g. he name of the logfile might contain the substring ' -sd '. Will masking substrings included in double quotes avoid such troubles?
Alternatively you can avoid -sd but use a dedicated function instead:
matlab -r "cd('/your/folder')"
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!