System programming - creating a shell

  • Thread starter Excluded_Middle
  • Start date
E

Excluded_Middle

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.
 
T

Tom St Denis

Excluded_Middle said:
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.

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
 
J

Jack Klein

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.

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.
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

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.
execvp(cmd,(char *)0) /* cmd is char cmd[200] */
it gives me error.

can any one explain why.

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.
 
R

Richard Heathfield

Jack said:
Either you or your teacher is insufficiently knowledgable. It is
literally not possible to perform IO redirection or pipes in ANSI C.

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

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.
 
C

Christopher Benson-Manica

Either you or your teacher is insufficiently knowledgable.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top