Article View: harvard.comp.unix
Article #4Re: C system command
From: Tony Curtis
Date: Mon, 27 Nov 1995 11:27
Date: Mon, 27 Nov 1995 11:27
38 lines
1634 bytes
1634 bytes
In article <49b2cg$4e3@decaxp.harvard.edu> sarmad@scunix4.harvard.edu (Shaikh Sarmad) writes:
Thank you Joev and Eugene for your suggestions. Both of the suggestions
work and I have solved my problem. Just wondering, which of the two
implementations would be more efficient (not that it's a problem!)
*** Joev's suggestion ***
: main (int argc, char **argv)
: {
: char cmd[100];
: sprintf(cmd, "finger -m %s", argv[1]);
: system(cmd);
: }
*** Eugene's suggestion ***
: main (int argc, char **argv)
: { char cmd [80];
: strcpy (cmd, "finger -m ");
: strcat (cmd, argv[1]);
: system (cmd);
: }
There is a problem with both of these though.
They do not check for overflow of the allocated space in `cmd'
What happens if argv[1]
a) does not exist?
b) is 156 chars long?
An execv() with dynamically allocated space would be the
better solution (I believe one was posted sometime).
tony
Technical Details
Message-ID:
<k6zqdis3gc.fsf@www.Austria.EU.net>Path:
arc1-ca.pugleaf.net!Austria.EU.net!usenetReferences:
<4997nh$sjj@decaxp.harvard.edu> <uufd9afhhri.fsf@scws27.harvard.edu> <49b2cg$4e3@decaxp.harvard.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!Austria.EU.net!usenet From: tony@Austria.EU.net (Tony Curtis) Newsgroups: harvard.comp.unix,comp.unix.questions,comp.lang.c Subject: Re: C system command Date: 27 Nov 1995 12:27:00 +0100 Organization: EUnet EDV-Dienstleistungs GmbH (Austria) Sender: tony@www.Austria.EU.net Message-ID: <k6zqdis3gc.fsf@www.Austria.EU.net> References: <4997nh$sjj@decaxp.harvard.edu> <uufd9afhhri.fsf@scws27.harvard.edu> <49b2cg$4e3@decaxp.harvard.edu> NNTP-Posting-Host: www.austria.eu.net In-reply-to: sarmad@scunix4.harvard.edu's message of 27 Nov 1995 00:56:48 GMT To: sarmad@scunix4.harvard.edu (Shaikh Sarmad) X-Newsreader: Gnus v5.0.8