Connecting Tech Pros Worldwide Forums | Help | Site Map

System programming - creating a shell

Excluded_Middle
Guest
 
Posts: n/a
#1: Nov 14 '05
Hi,
My teacher gave me an assignment to create a shell using ANSI C and
system calls. The shell is going to be very simple that can handle IO
redirection and pipes.

so far I create a program that prompts user and read commands using
scanf and then save this command in a string called cmd. then it uses
fork to create a child process and then execute the command using
execlp,my teacher said use execvp but it was giving me error. i.e when
I use


execvp(cmd,(char *)0) /* cmd is char cmd[200] */
it gives me error.

can any one explain why.

Tom St Denis
Guest
 
Posts: n/a
#2: Nov 14 '05

re: System programming - creating a shell



"Excluded_Middle" <sfrazq@hotmail.com> wrote in message
news:5f5518d0.0402032048.1be3d035@posting.google.c om...[color=blue]
> Hi,
> My teacher gave me an assignment to create a shell using ANSI C and
> system calls. The shell is going to be very simple that can handle IO
> redirection and pipes.
>
> so far I create a program that prompts user and read commands using
> scanf and then save this command in a string called cmd. then it uses
> fork to create a child process and then execute the command using
> execlp,my teacher said use execvp but it was giving me error. i.e when
> I use
>
>
> execvp(cmd,(char *)0) /* cmd is char cmd[200] */
> it gives me error.
>
> can any one explain why.[/color]

You called execvp wrong. [hint check the man pages]

Also seems you're posting from rogers. You wouldn't happen to be going to
Algonquin College would ya? Tisk tisk. Cheater.

Tom


Jack Klein
Guest
 
Posts: n/a
#3: Nov 14 '05

re: System programming - creating a shell


On 3 Feb 2004 20:48:45 -0800, sfrazq@hotmail.com (Excluded_Middle)
wrote in comp.lang.c:
[color=blue]
> Hi,
> My teacher gave me an assignment to create a shell using ANSI C and
> system calls. The shell is going to be very simple that can handle IO
> redirection and pipes.[/color]

Either you or your teacher is insufficiently knowledgable. It is
literally not possible to perform IO redirection or pipes in ANSI C.
On top of that, system calls are non-portable and not part of ANSI C
either. If your teacher literally told you to use those things in
ANSI C, your teacher does not know C and is unqualified to be teaching
the subject.
[color=blue]
> so far I create a program that prompts user and read commands using
> scanf and then save this command in a string called cmd. then it uses
> fork to create a child process and then execute the command using
> execlp,my teacher said use execvp but it was giving me error. i.e when
> I use[/color]

There are no such thing as "fork", "child process", or "execvp" in
ANSI C either. If your compiler supplies such things, they are
non-standard extensions it supplies, not part of C.
[color=blue]
> execvp(cmd,(char *)0) /* cmd is char cmd[200] */
> it gives me error.
>
> can any one explain why.[/color]

Nobody here will. We discuss the C language, not non-standard
extensions. You need to ask in a group that supports your particular
compiler/operating system combination.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Richard Heathfield
Guest
 
Posts: n/a
#4: Nov 14 '05

re: System programming - creating a shell


Jack Klein wrote:
[color=blue]
> On 3 Feb 2004 20:48:45 -0800, sfrazq@hotmail.com (Excluded_Middle)
> wrote in comp.lang.c:
>[color=green]
>> Hi,
>> My teacher gave me an assignment to create a shell using ANSI C and
>> system calls. The shell is going to be very simple that can handle IO
>> redirection and pipes.[/color]
>
> Either you or your teacher is insufficiently knowledgable. It is
> literally not possible to perform IO redirection or pipes in ANSI C.[/color]

You can, however, fake them if you're writing a shell.
[color=blue]
> On top of that, system calls are non-portable and not part of ANSI C
> either.[/color]

They don't have to be, if you just pass them on to a local command processor
and rely on the user to know what's legal for that command processor and
what isn't.

--
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Christopher Benson-Manica
Guest
 
Posts: n/a
#5: Nov 14 '05

re: System programming - creating a shell


Jack Klein <jackklein@spamcop.net> spoke thus:
[color=blue][color=green]
>> My teacher gave me an assignment to create a shell using ANSI C and
>> system calls.[/color][/color]
[color=blue]
> Either you or your teacher is insufficiently knowledgable.[/color]

The "and system calls" indicates that the assignment is both
well-defined and off-topic, at least as far as the system calls are
concerned.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Closed Thread