system(), shell, & stderr.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

system(), shell, & stderr.

Francesco Potorti`-7
   I have no control over which shell "system(cmd)" executes cmd in.
   It is whatever login shell the user has.

Seems not.  I have ksh as login shell, but
system("echo $0") --> "sh"

   Perhaps, an optional argument could be added to "system" to set
   the shell, or some global variable. (SHELL)

Yes.

   Also, perhaps system should have a mech. for trapping stderr,
   like it already does for stdout.

Not a bad idea.

   Without, reducing to a two-line shell script I can't see a way
   to redirect stderr shell-independently.

Why not:
system("sh -c 'date 2>/dev/null'") --> Mon Aug 28 11:34:32 MET DST 1995

However, it looks like this is not necessary, because system() always
uses sh, on the alpha precompiled binary I use.
--
         Francesco Potorti` | [hidden email] (Internet)
         researcher at | 39369::pot (DECnet)
         CNUCE-CNR, Pisa, Italy | +39-50-593203 (voice) 904052 (fax)

Reply | Threaded
Open this post in threaded view
|

Re: system(), shell, & stderr.

Christoph Mecklenbraeuker-2
Hi Rick, Francesco, and all other Octavers,

> system("echo $0") --> "sh"
This result also on Sun Workstations.

Christoph

============= email: [hidden email] =======================
Christoph Mecklenbraeuker             |
Lehrstuhl f. Signaltheorie (IC 5/35)  | Tel: +49(234) 700 6119
Ruhr Universitaet Bochum              | Fax: +49(234) 709 4261
D-44780 Bochum, Germany               |
======== http://www.sth.ruhr-uni-bochum.de/sth/whois/cfm/cfm.html =====

Reply | Threaded
Open this post in threaded view
|

system(), shell, & stderr.

John W. Eaton-6
In reply to this post by Francesco Potorti`-7
Francesco Potorti` <[hidden email]> wrote:

: Why not:
: system("sh -c 'date 2>/dev/null'") --> Mon Aug 28 11:34:32 MET DST 1995
:
: However, it looks like this is not necessary, because system() always
: uses sh, on the alpha precompiled binary I use.

Octave's system() function is implemented using a class derived from
the procbuf class in libg++, which implements a popen function.  The
code to exec the subprocess is

   _IO_execl("/bin/sh", "sh", "-c", command, NULL);

so your command should always be executed as a /bin/sh command,
provided that your system is Unix-like, you don't have a modified
version of libg++, and /bin/sh really is the Bourne shell.

I agree that it might be nice to make it possible to choose the shell,
but I don't think this is really necessary.  You should always be able
to do something like

  system (sprintf ("/bin/bash -c %s", command));

If your system really does use the login shell instead of /bin/sh for
Octave's system() function, can you try to debug why?

Thanks,

jwe

Reply | Threaded
Open this post in threaded view
|

Re: system(), shell, & stderr.

niles-3


>Octave's system() function is implemented using a class derived from
>the procbuf class in libg++, which implements a popen function.  The
>code to exec the subprocess is
>
>   _IO_execl("/bin/sh", "sh", "-c", command, NULL);
>
>so your command should always be executed as a /bin/sh command,


Ok so it was a dumb question, but what I really want to do is
put a process in the background.
e.g. system("emacs &")

However, I don't get the octave prompt back until I exit emacs.

I noticed system("emacs > /dev/tty &") does work!

I guess this is what one has to do to run a process in the background.

        Thanks and sorry for the dumb question,
        Rick Niles.