Re: exec() bug in handling embedded blanks
Posted by
Neil Fazel on
Jul 22, 2014; 3:53pm
URL: http://imagej.273.s1.nabble.com/exec-bug-in-handling-embedded-blanks-tp5008844p5008849.html
Hi Michael,
Thanks for the useful tip; I switched to using "sh -c" and was able to get it to work. A couple of remarks:
1) "sh -c" seems to require that the argument passed to it be itself a string, i.e. quoted. This would require 3 levels of quoting. I tried this (note the escaping of the innermost double quotes):
cmd="sh -c \"ls '" + directory + "/'*avg.txt\"";
exec(cmd);
and it didn't work (even though copying & pasting the value of "cmd" to the Unix prompt did work). What finally worked inside the macro was this syntax:
exec("sh", "-c", "ls '" + directory + "/'*.txt"),
2) If the "sh -c" syntax causes the Unix shell to take control, what happens without it? In order to run a native command, doesn't ImageJ have to pass on exec()'s argument to the Unix shell, even in the absence of "sh -c"?
Thanks for the code snippet.
Best regards,
Neil
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html