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

Karl Auer kauer at biplane.com.au
Tue May 17 11:56:42 UTC 2016


On Tue, 2016-05-17 at 05:31 -0400, Frank Chang wrote:
> mono-service2 myservice.exe -l:/var/run/test --debug > log.txt

That works in a shell, which understands the ">" syntax to mean
"redirect standard output". A C++ program does not understand that.

>   char *argv[] = { "/usr/lib/mono/4.5/mono-service.exe",
>                     "Audio_Video_Recorder.exe", "--debug", ">&",
> "./LOGCamster.txt", 0};

I'm not sure, but to use the ">" syntax I think you may have to exec a
shell, and pass the rest as a command pipe for the shell to execute. Or
run your C++ program with output redirected.

You could also put everything you want in a script, then run the script
via execvp() of a shell. Not very safe, but it would get you started.

It would be better if you redirected stdout (and probably stderr)
directly, within your program. C++ refers to those streams as std::cout
and std::cerr. Check out the freopen() function.

Google for "redirect stdout in C++".

Why are you doing this with C++? If all you want to do is run something
as a service, there are much better ways, many of which have been
discussed here in responses to your questions. You are reinventing the
wheel.

Regards, K.

PS: This C++ stuff is not Ubuntu. You would be better served by a C++
programming forum.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer






More information about the ubuntu-users mailing list