Article View: comp.unix
Article #752Re: system command
From: Dan Mercer
Date: Thu, 29 Jun 1995 00:00
Date: Thu, 29 Jun 1995 00:00
83 lines
3527 bytes
3527 bytes
Joe Yang (yang@math.duke.edu) wrote:
: In article <3sprhr$6g6@venera.isi.edu>, Gaurav Singh <gsingh@isi.edu> wrote:
: >
: >Hi,
: >
: > I am trying to execute the "system" command to execute an application
: >(executable program).
: >However the system command does not work if the name of the application has been
: >aliased.
: >
: > e.g: $ alias test ps
: > $ test
: > (this works)
: >
: > however system("test"); in a c-program does not work.
: >
: > sh: test: not found
: >
: >
: > I wonder if there is a way to force the system command to take into
: >account the aliases, or is there a more efficient way to invoke an application
: >from a c-program.
: >
: The reason this doesn't work is because the "system" library routine
: spawns a Bourne shell process first, then execute the command in the
: new shell. First of all, aliases are not part of the environment
: inherited by a child process ("sh" in this case), secondly, alias is
: a C shell command and Boune shell doesn't even understand it.
One quibble - a POSIX compatible system (and popen) execls
"/bin/posix/sh" which does support aliases. However the syntax,
sh -cQ "command"
doesn't allow aliases.
Now, does anyon know what the Q does?
: "system" is not a good way (although convinient) to apawn another
: program in a C program anyway, one of the disadventage is the overhead
: because another shell process is spawned unnecessarily. Try using
: system call "fork" to create a new process directly and then using
: exec (or one of its variations) to execute the new program. Now this
: will not solve your alias program, because an alias is not a physical
: program. Is there any particular reason you have to use an alias?
: this will make your grogram very "unportable" even from shell to
: shell.
: Rose Sun
: rose@ais.com
:
: > pl reply to this news group or to gsingh@isi.edu
: >
: >
: > thanks a ton
: >
: > Gaurav
: >
: >
: >
: >
: >
: >
: >
: >
: >
--
Dan Mercer ClearSystems, Inc
Reply To: damercer@mmm.com "The Mad Pedant"
======================================================================
All opinions expressed are my own and do not reflect the opinions of
my employer or my employer's clients, in particular 3M Company.
All advice or software offered or presented is provided As Is with no
warranty either expressed or implied. Follow at your own risk.
Objects in the mirror are closer than they appear.
Technical Details
Message-ID:
<3sv79a$jug@dawn.mmm.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3suhtc$bi4@news.duke.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8c9b,f653ab8f84d6a686 X-Google-Attributes: gidf8c9b,public X-Google-Thread: f72b0,f653ab8f84d6a686 X-Google-Attributes: gidf72b0,public X-Google-Thread: fc89c,f653ab8f84d6a686 X-Google-Attributes: gidfc89c,public X-Google-Thread: 10183f,f653ab8f84d6a686 X-Google-Attributes: gid10183f,public X-Google-Thread: 10f717,f653ab8f84d6a686 X-Google-Attributes: gid10f717,public X-Google-Thread: 1012a6,f653ab8f84d6a686 X-Google-Attributes: gid1012a6,public From: dam@medlab9.mmm.com (Dan Mercer) Subject: Re: system command Date: 1995/06/29 Message-ID: <3sv79a$jug@dawn.mmm.com> X-Deja-AN: 105262609 references: <3suhtc$bi4@news.duke.edu> organization: ClearSystems, Inc followup-to: comp.unix,ca.unix,comp.unix.misc,comp.unix.programmer,comp.unix.questions,comp.unix.shell newsgroups: comp.unix,ca.unix,comp.unix.misc,comp.unix.programmer,comp.unix.questions,comp.unix.shell