UNIX shell scripts/commands..?? 
Author Message
 UNIX shell scripts/commands..??

What is the preferred method for running UNIX shell scripts or commands
from with ANSI C?  Are there problems with doing so with different shell
variants?  That is, would the procedure be different for /bash vs. /tcsh??

...dtw


--
"Society everywhere is in {*filter*} against the manhood of every one of its
members.  Society is a joint-stock company, in which the members agree, for the
better securing of his bread to each shareholder, to surrender the liberty and
culture of the eater.  The virtue in most request is conformity. Self-reliance
is its aversion.  It loves not realities and creators, but names and customs.
Whoso would be a man, must be a nonconformist."
                                                 -R. W. Emerson



Mon, 06 Oct 1997 03:00:00 GMT  
 UNIX shell scripts/commands..??

Quote:
>What is the preferred method for running UNIX shell scripts or commands
>from with ANSI C?  Are there problems with doing so with different shell
>variants?  That is, would the procedure be different for /bash vs. /tcsh??

There is only one ANSI C method for running external scripts/commands:
system().  

In Unix, system() passes its argument to a Bourne shell to be interpreted
and executed as a command line, so you can take advantage of all the sh
features.  Of course, you can start scripts written in whatever
scripting language you want.

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Tue, 07 Oct 1997 03:00:00 GMT  
 UNIX shell scripts/commands..??
Quote:
>What is the preferred method for running UNIX shell scripts or commands
>from with ANSI C?  Are there problems with doing so with different shell
>variants?  That is, would the procedure be different for /bash vs.

/tcsh??

    I use the system command all the time, and execl sometimes.

  If your shell scripts start with #!/bin/sh to force the shell type,
things are easier.  If you have arguments you need to pass, do something
like:
sprintf(cmd,"lpc stop %s",prt);
system(cmd);

   to force a specific shell you could:
sprintf(cmd,"/bin/csh -c %s",shell_cmd);

    system();
 +
    +  Centauri
  +



Sun, 12 Oct 1997 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. unix shell script execution

2. A C program that calls unix shell scripts

3. how to call a unix shell script from a c program

4. Invoking sendmail/mail shell commands in a CGI script

5. From a Unix shell script to a C function

6. How can i return a variable to a Unix shell script

7. unix shell command line and interpreter

8. returning output of UNIX shell commands

9. Capturing Output from a Shell Command in UNIX

10. Running a shell script from C program

11. Calling a KORN shell script (AIX) from a C-program

12. Change shell script to C ?

 

 
Powered by phpBB® Forum Software