Re: macro: Redirection in exec( UNIX-binary ) ?
Posted by
dscho on
Jul 28, 2010; 10:29am
URL: http://imagej.273.s1.nabble.com/macro-Redirection-in-exec-UNIX-binary-tp3687463p3687466.html
Hi,
On Wed, 28 Jul 2010, Michael Schmid wrote:
> there is a trick to do it, using the shell with '-c commandstring'
> e.g.
> exec("/bin/sh", "-c", "pwd >/tmp/test");
> writes the output of the 'pwd' command to /tmp/test
Good call! (Even if it forks two processes instead of one.)
You now have to watch out to quote arguments containing whitespace,
though.
> The -c switch works at least with bash, I am not sure about the original
> Bourne shell.
From
http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html we
can see that all POSIX-conforming shells support both the '-c' option and
redirection.
Ciao,
Johannes