Problem running an exe with path containing spaces, while saving command output

78 ビュー (過去 30 日間)
street_car
street_car 2021 年 2 月 25 日
コメント済み: street_car 2021 年 2 月 25 日
Hello,
I have a weird problem in MATLAB. I'm trying to run an exe, say test.exe. This is in a folder/directory which has spaces in the name. C:\users\abc\test folder\test.exe. I'm saving the path to a variable so I don't have to type it out everytime, and the code is cleaner.
I see a very weird problem. The space in the path causes a problem only if I have to save the command output. Interestingly, the problem doesn't occur if I run the exe without any arguments. In this case the cmdout is properly logged (like most exes, this exe gives usage instructions when you run it without any arguments)
exe_path = 'C:\users\abc\test folder\test.exe';
% No output saving - no problem
system([exe_path,' arg1'])
>> NO PROBLEM
% Output saving - problem
[status, cmdout] = system([exe_path,' arg1'])
>> ''C:\users\abc\test' is not recognized as an internal or external command, operable program or batch file'
% Interesting twist - no arg1 works fine
[status, cmdout] = system(exe_path)
>> NO PROBLEM
I've tried double quotes, single quotes, single and double quotes (based on some other answers), but I can't fix this isssue. The simple solution would be to move the exe or rename the folder, but this is a common install path for anyone in my ecosystem installing the tool and there are a lot of dependent dlls that the exe uses. Moving all this to a new folder will place a lot of dependencies when I will have to distribute the utility I am trying to create in MATLAB.
Let me know if there is a fix for the above problem.

採用された回答

Stephen23
Stephen23 2021 年 2 月 25 日
Specify double-quotes at each end of the path, e.g.:
exe_path = '"C:\users\abc\test folder\test.exe"';
  1 件のコメント
street_car
street_car 2021 年 2 月 25 日
Yeah, just realized that on my end also! Thank you for the suggestion!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by