LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-02-2010, 07:27 AM   #1
whirlpool
LQ Newbie
 
Registered: Aug 2010
Posts: 11

Rep: Reputation: 3
Unhappy How to write a replacement for shell command line interpreter


Hey,
If say, I want to read the input given by user at the command prompt and write a code to execute the cmd given then which commands do i use to implement this ( Im writing the code in C )?
Please give me a hint as to how do i start ?

Thanks
Ambika
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-02-2010, 07:31 AM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
I'd use the readline library for taking the input, full line editing capabilities. As far as executing the command you'd probably want to do a fork and then exec (from the child process of the fork)
 
Old 09-02-2010, 09:23 AM   #3
giammy
Member
 
Registered: Feb 2010
Posts: 36

Rep: Reputation: 20
Quote:
Originally Posted by whirlpool View Post
Hey,
If say, I want to read the input given by user at the command prompt and write a code to execute the cmd given then which commands do i use to implement this ( Im writing the code in C )?
Please give me a hint as to how do i start ?

Thanks
Ambika
Hi,

I would look for this in Google ... something such as the following could come out :-)
http://rik0.altervista.org/snippets/csimpleshell.html

bye
giammy
 
2 members found this post helpful.
Old 09-03-2010, 12:51 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
In this particular case, google would be a good idea, not because I don't want to help you (I do), but because that is a very popular homework / project question in college, as a result of which, there are loads of comments/tips on this very qn on the internet by now.
 
Old 09-03-2010, 01:29 AM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
See if this thread helps you :
http://www.linuxquestions.org/questi...-shell-775690/

and the Programming questions should be placed here:http://www.linuxquestions.org/questions/programming-9/

Last edited by Aquarius_Girl; 09-03-2010 at 01:31 AM.
 
Old 09-05-2010, 02:27 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 09-05-2010, 02:30 AM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by estabroo View Post
I'd use the readline library for taking the input, full line editing capabilities. As far as executing the command you'd probably want to do a fork and then exec (from the child process of the fork)
'system' is simpler than 'fork', 'exec' to use and probably is sufficient in this case.
 
Old 09-05-2010, 08:12 AM   #8
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by Sergei Steshenko View Post
'system' is simpler than 'fork', 'exec' to use and probably is sufficient in this case.
It is simpler but why involve yet another shell when you are trying to replace one.

With fork/exec you have more control over how the parent deals with the child process, for example how it's stdin/stdout/stderr are attached, or what other file descriptors are left open for the child to access, or being able to send the child process signals.

I guess it just depends on what the OP wants to get out of this coding exercise.
 
Old 09-06-2010, 07:20 AM   #9
whirlpool
LQ Newbie
 
Registered: Aug 2010
Posts: 11

Original Poster
Rep: Reputation: 3
Thanks

Thanks to all for the help offered.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting a command line interpreter when using Gnome Desktop: 3 different ways??? jayrolldotorg Linux - Newbie 8 03-30-2010 04:56 PM
need to write a shell script for appending text into each line of a file nandakv4 Programming 9 08-15-2009 03:32 AM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 06:30 PM
Command Line Interpreter prady Linux - Newbie 1 02-19-2006 09:58 PM
scheme interpreter w/ command-line editing nazdrowie Programming 1 12-03-2004 08:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration