MATLAB-extension-for-vscode icon indicating copy to clipboard operation
MATLAB-extension-for-vscode copied to clipboard

pwd() output not correct during execution of startup.m

Open robertoffmoura opened this issue 11 months ago • 3 comments

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:

  1. Edit startup.m and add this line listdlg("pwd", pwd())
  2. Open a new VS Code session
  3. Open a folder (cntrl+K cntrl+O)
  4. Open a new MATLAB terminal
  5. 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.

robertoffmoura avatar Mar 11 '25 12:03 robertoffmoura

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?

dklilley avatar Mar 11 '25 13:03 dklilley

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")

robertoffmoura avatar Mar 11 '25 16:03 robertoffmoura

Thanks for sharing that info!

We will consider this for a future update of the extension.

dklilley avatar Mar 13 '25 14:03 dklilley