🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

5 total messages Started by Gaurav Singh Tue, 27 Jun 1995 00:00
system command
#751
Author: Gaurav Singh
Date: Tue, 27 Jun 1995 00:00
31 lines
1492 bytes




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.

	pl reply to this news group or to gsingh@isi.edu


	thanks a ton

	Gaurav
Re: system command
#753
Author: Joe Yang
Date: Thu, 29 Jun 1995 00:00
61 lines
2550 bytes
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.

"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
>
>
>
>
>
>
>
>
>
Re: system command
#754
Author: steve johnson
Date: Thu, 29 Jun 1995 00:00
11 lines
1259 bytes
In article <3suhtc$bi4@news.duke.edu>, yang@math.duke.edu (Joe Yang) wrote:

> "system" is not a good way (although convinient) to apawn another
> program in a C program anyway, 

how about in a csh script?  good?  bad?

-- 
"Wheeeee, doggies!"

                     - jed clampett
Re: system command
#755
Author: Landslidius MarXaMis
Date: Wed, 05 Jul 1995 00:00
26 lines
1536 bytes
In article <3sprhr$6g6@venera.isi.edu>, gsingh@isi.edu (Gaurav Singh) says:

>
>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
>


looks to me like you're shelling out to a bourne shell, judging
from your err msg, and the alias cmd is in the C shell.

off the top of my head try:

		system("tcsh test");
Re: system command
#756
Author: Thanh Ma
Date: Thu, 06 Jul 1995 00:00
33 lines
1725 bytes
markjr@shmooze.net (Landslidius MarXaMis) writes:

>In article <3sprhr$6g6@venera.isi.edu>, gsingh@isi.edu (Gaurav Singh) says:

>>
>>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
>>


>looks to me like you're shelling out to a bourne shell, judging
>from your err msg, and the alias cmd is in the C shell.

>off the top of my head try:

>		system("tcsh test");

or specify the full pathname of test.

Thanh Ma
tma@encore.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads