Why Ubuntu 16.04 C++ program cannot programatically stop mono-service?

Paul Smith paul at mad-scientist.net
Wed May 18 16:05:25 UTC 2016


On Wed, 2016-05-18 at 17:49 +0200, Tom H wrote:
> On Wed, May 18, 2016 at 5:24 PM, Oliver Grawert <ogra at ubuntu.com>
> wrote:
> > Am Dienstag, den 17.05.2016, 10:26 -0400 schrieb Frank Chang:
> >>
> >> I tried char *argv[] = {"/bin/sh", "mono-service.exe",
> >> "Audio_Recorder.exe", "--debug", ">&", "log.txt",0) followed by
> >> execve(argv[0], &argv[0], envp) with no success.

Sure.  If you try running that same thing from the command prompt you'll
see it doesn't work at all:

  /bin/sh mono-service.exe Audio_Recorder.exe --debug >& log.txt

If you want to run a shell and have the shell run a command you need to
use the "-c" option, then pass the entire command as a single argument:

  "/bin/sh", "-c",  "mono-service.exe Audio_Recorder.exe --debug >log.txt 2>&1"

It's a little odd that your programs have "exe" extensions on Linux, but
whatever.

> > ">&" is a "bashism" ... use proper POSIX shell for the redirect or
> > call /bin/bash instead of /bin/sh ...
> 
> Are you sure?
> 
> From "man dash":
> 
> [n1]>&n2 Duplicate standard output (or n1) to n2

Yes.  "1>&2" (or generally, [n1]>&n2) has been part of the shell since
forever and is required by POSIX.

But ">&", which is what the original poster used, does not match the
pattern "[n1]>&n2" so it's not covered by that statement in the man
page.  It's a shortcut that bash (and some other shells) added.




More information about the ubuntu-users mailing list