🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #1261

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

#1261
From: Gary Weimer
Date: Tue, 20 Nov 1990 15:06
31 lines
2084 bytes
In article <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:
>
>		for (i = 2; i < MAX_ARGS && (s = strtok (command, " \t")); i++)
>			args [i] = strsave (s);
>
>I am using C shell and System V. I tried `/bin/ls -l -R' as input to
>shell_escape (), my .login file gets executed here and /bin/ls is executed
>(without -l -R) options. 
>
>Can some body help me with this problem? 

From the man page for strtok:

     strtok() considers the string s1 to consist of a sequence of
     zero  or  more text tokens separated by spans of one or more
     characters from the separator string  s2.   The  first  call
     (with  pointer  s1 specified) returns a pointer to the first
     character of the first token, and will have written  a  null
     character  into s1 immediately following the returned token.
     The function keeps track  of  its  position  in  the  string
     between separate calls, so that subsequent calls (which must
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     be made with the first argument a NULL  pointer)  will  work
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     through  the string s1 immediately following that token.  In
     this way subsequent calls will work through  the  string  s1
     until no tokens remain.  The separator string s2 may be dif-
     ferent from call to call.  When no token remains  in  s1,  a
     NULL pointer is returned.
Technical Details
Message-ID: <1990Nov20.150635.22378@ssd.kodak.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sdd.hp.com!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!kodak!ispd-newsserver!weimer
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!samsung!sdd.hp.com!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!kodak!ispd-newsserver!weimer
From: weimer@ssd.kodak.com (Gary Weimer)
Newsgroups: comp.unix.programmer
Subject: Re: How to provide Shell Escape from a C program?
Message-ID: <1990Nov20.150635.22378@ssd.kodak.com>
Date: 20 Nov 90 15:06:35 GMT
References: <349@clbull.cl.bull.fr>
Sender: news@ssd.kodak.com
Organization: Eastman Kodak
Lines: 31