🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #1267

Re: How to provide Shell Escape from a C program?

#1267
From: Norman Joseph
Date: Wed, 21 Nov 1990 14:16
34 lines
1753 bytes
In <349@clbull.cl.bull.fr> rudrak@saphir.cl.bull.fr (Rudrakshala Purushotham)
writes:

>I want to provide shell escape feature from a C program. But I am having 
>some problems with the following code:

You are doing more work than you have to.  Your "shell_escape( command )"
has already been written for you.  It is called "system()".  Look for it
in your manual.  As for your code:

>	char *args [MAX_ARGS];
>	args [0] = "/bin/sh";
>	args [1] = "-c";

>	for (i = 2; i < MAX_ARGS && (s = strtok (command, " \t")); i++)
>		args [i] = strsave (s);

>	args [i] = NULL;

To properly use strtok() you only pass it the string you want to parse
once.  To return successive tokens from the string, the first argument
should be a null pointer in all successive calls.  The idiom goes
something like this:

	s = strtok( command, " \t" );
	args[2] = strsave( s );
	for ( i = 3;  i < MAX_ARGS && ( s = strtok( NULL, " \t" ));  i++ )
		args[i] = strsave( s );
	args[i] = NULL;
-- 
Norm Joseph - (amanue!oglvee!norm)           cgh!amanue!oglvee!norm@dsi.com, or
  Oglevee Computer Systems, Inc.             ditka!oglvee!norm@daver.bungi.com
                                   ---<*>---
      "Shucking Usenet oysters in pursuit of a pearl."  --  Bill Kennedy
Technical Details
Message-ID: <622@oglvee.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!pitt!amanue!oglvee!norm
References: <349@clbull.cl.bull.fr>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!pitt!amanue!oglvee!norm
From: norm@oglvee.UUCP (Norman Joseph)
Newsgroups: comp.unix.programmer
Subject: Re: How to provide Shell Escape from a C program?
Message-ID: <622@oglvee.UUCP>
Date: 21 Nov 90 14:16:14 GMT
References: <349@clbull.cl.bull.fr>
Organization: Oglevee Computer Systems, Connellsville, Pa
Lines: 34