File names with spaces used as command line arguments
古いコメントを表示
I am trying to run an external program with command line arguments. The syntax is like this:
bertini <inputFile> <startpointFile>
The problem is, if one of the files in the command line has a space in its name, I can't get it to work. For example, if commandStr = 'bertini paramotopy.input /Users/my folder/start', then
[status,result] = system(str)
returns an error because bertini thinks the startpoint file is /Users/my.
I have not been able to make any of the usual suggestions involving backslashes or double quotes work for this example. I need it to work for both Windows and Unix-based systems.
Comment added: Bertini is not a Matlab executable; it is an entirely separate product that was written in C. Unfortunately, I don't have the option of altering its code. Sorry for the misunderstanding - it didn't occur to me that people would assume this.
採用された回答
その他の回答 (3 件)
Robert Cumming
2014 年 7 月 25 日
編集済み: Robert Cumming
2014 年 7 月 26 日
try putting " around the command,
commandStr = '"bertini paramotopy.input /Users/my folder/start"'
edit
So the problem is running the bertin code - I would first try to get that working on its own from the command line the way you want it to (it might not be possible...) then transfer that methodology into the system command.
The input parser for your c code is space delimited - so it will be interpreting your 2 commands as 3 (since the 2nd has a space in it...).
2 件のコメント
Andrew Newell
2014 年 7 月 25 日
Robert Cumming
2014 年 7 月 25 日
ah sorry misunderstood. try single quotes or can you pass a file in. Ultimately this is an issue with bertini api and not really matlab
Sean de Wolski
2014 年 7 月 25 日
Perhaps try the ! operator:
!bertini paramotopy.input /Users/my folder/start
2 件のコメント
Andrew Newell
2014 年 7 月 25 日
Image Analyst
2014 年 7 月 25 日
編集済み: Image Analyst
2014 年 7 月 25 日
Did you try what I showed you? Assuming "bertini" is the MATLAB-code executable that you compiled into a standalone executable, and are trying to pass in arguments for, I know for a fact that this will work. I've been through what you're going through and basically I had to "rebuild" the command line from the parts. I know it works because I use it in my systems all the time.
per isakson
2014 年 7 月 25 日
This should work at least on Windows
commandStr = 'bertini paramotopy.input "/Users/my folder/start"';
[status,result] = system( commandStr );
if not what does result say?
5 件のコメント
Image Analyst
2014 年 7 月 25 日
It's been a while but I'm pretty sure that doesn't work when passed in to a MATLAB executable. Andrew and I both tried that. That's why he's asking - note he said he tried double quotes. And that's why I did the method I showed.
per isakson
2014 年 7 月 25 日
- "when passed in to a MATLAB executable"   Is the problem with "compiled" Matlab code? I assumed it was interpreted mode.
- the problem might be special to bertini
- I usually use absolute paths
Image Analyst
2014 年 7 月 26 日
編集済み: Image Analyst
2014 年 7 月 26 日
I assumed that "MATLAB executable" means that he compiled his m-file, bertini.m, into a standalone executable. In that case he will observe the situation that he and I both did. However his latest edit indicates it's not a MATLAB executable but some other program. In that case, it's up to the other program to handle it properly, which it does not.
In my code I also use absolute paths. If you try to pass an absolute path into a MATLAB executable, with spaces in it, in as a command line argument you will have a problem. Say another program launches your MATLAB executable, and wants to feed it some folder on the command line. The executable will interpret it as multiple arguments regardless if it's enclosed in single or double quotes or just bare. Again, we learned that it's not his situation anymore.
per isakson
2014 年 7 月 26 日
編集済み: per isakson
2014 年 7 月 26 日
I would try
bertini paramotopy.input "/Users/my folder/start"
at Windows Command Prompt (the DOS window).
Image Analyst
2014 年 7 月 26 日
Good suggestion. If it fails, then we know it has nothing to do with MATLAB and it's all bertini's fault.
カテゴリ
ヘルプ センター および File Exchange で Scripts についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!