[comp.unix.questions] Using csh commands within the system

saf@tnl.UUCP (friedman scott) (01/14/90)

I wish to use a system command that works under csh but not under sh within
a system() function call in a C program.  The line looks something like this:

   system("command_that_generates_errors >& /dev/null");

When this runs, I get an error like:

   sh: /dev/null: bad number

After looking up the system() call, I see that it will interpret the
argument as a sh command.  How do I get system() to interpret the argument
as a csh command?

                               Scott Friedman

cpcahil@virtech.uucp (Conor P. Cahill) (01/14/90)

In article <239@tnl.UUCP>, saf@tnl.UUCP (friedman scott) writes:
> I wish to use a system command that works under csh but not under sh within
> a system() function call in a C program.  The line looks something like this:
> 
>    system("command_that_generates_errors >& /dev/null");


You could modify it so that it will work under sh (like the following):

     system("command_that_generates_errors > /dev/null 2>&1");

or you could fork and execute the program yourself, mapping stdout and stderr
   to /dev/null.

or you could write a new system() like program (maybe csystem()) that

	forks
	if child runs csh -c arg_string;
	waits
	returns



-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

jik@athena.mit.edu (Jonathan I. Kamens) (01/15/90)

In article <1990Jan13.213312.6620@virtech.uucp>, cpcahil@virtech.uucp (Conor P.
Cahill) writes:
> In article <239@tnl.UUCP>, saf@tnl.UUCP (friedman scott) writes:
> > I wish to use a system command that works under csh but not under sh within
> > a system() function call in a C program.  The line looks something
like this:
> > 
> >    system("command_that_generates_errors >& /dev/null");
> 
> [suggests modifying the command to work under sh, or forking and execing the
>  process without using system, or writing a new system function to use csh]

  Or, you could just use the easiest solution, which is to tell /bin/sh
to use /bin/csh when parsing the command:

    system("/bin/csh -fc 'command_which_generates_errors >& /dev/null'");

(Yes, I know that if the /bin/csh which is executed prints out an error,
then it will be printed in the calling process.  I don't consider that
such a bad thing, given that if the shell has to print out an error then
there is something very wrong....)

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710