shinyypig / matlab-in-vscode

A vscode extension for matlab.
MIT License
45 stars 5 forks source link

Pybackend quotes in Windows #25

Closed oletf closed 1 year ago

oletf commented 1 year ago

Hi,

The triple double quotes here seem to disturb windows cmd and the whole addpath for the variable_info function is never added (as well as the pwd). They might be escaped somehow.

C:\Users\user\project>py -3.5 "c:\Users\user\.vscode\extensions\shinyypig.matlab-in-vscode-0.4.16\pybackend\matlab_engine.py" --cmd="""disp(['Working directory: ', pwd]);addpath('c:\Users\user\.vscode\extensions\shinyypig.matlab-in-vscode-0.4.16\matlab_code\');"""
---------------------------------------------------------
MATLAB Engine for Python is ready (terminate with 'quit')
---------------------------------------------------------

ans =

    "disp(['Working directory: ', pwd]);addpath('c:\Users\user\.vscode\extensions\shinyypig.matlab-in-vscode-0.4.16\matlab_code\');"

>>> variable_info;

Error using eval
Undefined function or variable 'variable_info'.

>>>

I tried just replacing the triple by simple double quotes and it works perfectly, but I don't know if it'll break anything on Unix based shells.

-                    ` "${scriptPath}" --cmd="""${startupCommand}"""`;
+                    ` "${scriptPath}" --cmd="${startupCommand}"`;
oletf commented 1 year ago

also related enough, the runMatlabFile function doesn't work on my side because Matlab's run function in versions prior to R2018 only takes a character vector as scriptname arg (and not a string scalar | character vector).

As version R2023 still accepts character vector for this native function, changing with

-            let matlabCommand = `run("${relativePath}")`;
+            let matlabCommand = `run('${relativePath}')`;

shouldn't break anything in versions R2018 and after (confirmed it works on my side, but would need check on other versions just in case).

shinyypig commented 1 year ago

Thank you for your contribution! I have confirmed that it also works on macOS. The relevant code has been updated in version 0.4.17.

Once again, thank you for your assistance!