LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 02-24-2007, 06:29 PM   #1
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Rep: Reputation: 15
"cd" command from C language


Hi,
How do I execute cd command from C language ? Execvp is not helping me out. Other commands are running fine from execvp, but some of the commands like cd are not working.

Any suggestions ??
 
Old 02-24-2007, 06:41 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
man chdir

The current directory is a part of the enviroment of a process. A child process cannot mess with its parent's enviroment, so the cd done in the child is lost.

What are you trying to do, anyway? execvp() and friends aren't used that much in programs.
 
Old 02-24-2007, 07:05 PM   #3
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Original Poster
Rep: Reputation: 15
well that is a part of our assignment, we need to simulate a shell from where i can run commands...

that is what i am confused with, if i do cd and then move on to other directories, how will the process keep on continuing ?
 
Old 02-24-2007, 07:20 PM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
That's because the child process has its own idea of what is its current directory. It won't change because the parent process changes its current directory. The current directory of a process is in its enviroment, and the enviroments of a parent and child are distinct and independent. The cd command *must* be a shell builtin. In fact, there usually isn't even a cd binary on the system, so you shouldn't even be able to use execvp to run cd.
 
  


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
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
cdrecord command-line parentheses "(" ")" coolingtower Linux - Software 1 10-28-2005 11:49 AM
"stalled" problem in " scp" command gentleshark Linux - Networking 1 08-29-2005 12:41 PM
Tiny Sofa 2.0 - I thought "halt", "reboot" were only root command ?? sorcerer Linux - Distributions 1 08-21-2004 03:28 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-21-2003 11:47 PM

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

All times are GMT -5. The time now is 06:56 AM.

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