pwd() output not correct during execution of startup.m
Describe the bug if I type pwd() in the terminal it will print the directory that I selected when opening a folder in VS Code. However, that doesn't happen when pwd() is run as part of startup.m.
To Reproduce Steps to reproduce the behavior:
- Edit startup.m and add this line
listdlg("pwd", pwd()) - Open a new VS Code session
- Open a folder (cntrl+K cntrl+O)
- Open a new MATLAB terminal
- A popup window will display a directory that is not the opened folder.
Expected behavior pwd() should return the opened folder.
Useful Information OS Version: "Red Hat Enterprise Linux" VERSION="8.10 (Ootpa)" VS Code Version: 1.96.2
Additional context Typing pwd() after startup.m has finished running returns the opened folder.
Thanks for reaching out about this!
This is the current expected behavior, as we do not change MATLAB's current directory until after it has launched.
Can you share any details about why it is important that the current directory be updated prior to startup executing?
I have a script to automatically set the MATLAB paths which depends on the repo I'm working on. I'd like to execute this script automatically when the extension starts. It would be very useful if I could know which folder VS Code has opened during the execution of startup.m.
I've tried these environment variables as well but none of them return the directory that is currently open on VS Code:
getenv("PWD") getenv("VSCODE_CWD") getenv("HOME")
Thanks for sharing that info!
We will consider this for a future update of the extension.