473,782 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

programmaticall y change directory in UNIX

hi,
please do let me know how i can change the directory through my
program and retain it too after i exit; if there's a way to do it.
regards,
varun yagain.
Nov 13 '05 #1
3 13918
Varun Yagain wrote:
hi,
please do let me know how i can change the directory through my
program and retain it too after i exit; if there's a way to do it.
regards,
varun yagain.


This question is not apropriate for clc. comp.unix.progr ammer is a better
place.

<OT>
You can't. That's why cd has to be shell builtin and not an external
command.
<\OT>

Tobias

--
unix http://www.faqs.org/faqs/by-newsgrou...rogrammer.html
clc http://www.eskimo.com/~scs/C-faq/top.html
fclc (french): http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #2
On 24 Jul 2003 12:37:00 -0700, va*********@red iffmail.com (Varun Yagain) wrote:
hi,
please do let me know how i can change the directory through my
program and retain it too after i exit; if there's a way to do it.
regards,


First off, this is off-topic for C.L.C

2nd, look at the chdir(2) function for the Unix way to "change directories"

3rd. You aren't going to be able to retain the new directory after you exit.
That's not how Unix works.
--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
Nov 13 '05 #3
In <75************ **************@ posting.google. com> va*********@red iffmail.com (Varun Yagain) writes:
please do let me know how i can change the directory through my
program and retain it too after i exit; if there's a way to do it.


The current working directory is a property of the program. It is
not passed back to the "parent" process, so this piece of information
is normally lost when the program terminates.

It is always possible to do something about it, just don't expect it
to happen by magic:

fangorn:~/tmp 1921> pwd
/afs/ifh.de/user/d/danpop/tmp
fangorn:~/tmp 1922> cat test.c
#include <stdio.h>
#include <unistd.h>

char buff[FILENAME_MAX];

int main()
{
chdir("/usr/bin");
if (getcwd(buff, sizeof buff) != NULL) puts(buff);
else puts("unknown") ;
return 0;
}
fangorn:~/tmp 1923> gcc test.c
fangorn:~/tmp 1924> cd `./a.out`
fangorn:/usr/bin 1925> pwd
/usr/bin

Of course, this approach works only as long as you don't use stdout for
any other purposes...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2834
by: just1coder | last post by:
Is there a way to programmatically change the base href tag in a website with JavaScript?
2
2548
by: Samuel Yin | last post by:
Hi, guys, This should be a simple problem, but I just can not resolve it. I just want to use a python script to change my working directory. see my following code: # mycd.py 1) destdir = "xxxxxxxx" 2) command = "cd "+ destdir 3) os.system(command)
0
853
by: The Truth | last post by:
All, How can I programmatically change the binding order of the network protocol in Win XP using VC++. Thanks in advance.
1
7990
by: Craig | last post by:
How do I programmatically change the text property of a label in an ItemTemplate in a datagrid? Specifically the Text property. I want to change the databinding to another column at runtime. <asp:TemplateColumn HeaderText="Rate1"> <ItemTemplate> <asp:Label runat="server" Text='<%# fRate(DataBinder.Eval(Container, "DataItem.RateAgentID")) %>' ID="Label3" NAME="Label3"> </asp:Label>
1
1212
by: thibaut | last post by:
Hi, Is it possible to programmatically change iis rights on a file or a directory (allow write access on xml files, deny download for databases,...). Thanks for your help
1
5672
by: Tony Girgenti | last post by:
Hello. I'm trying to write a simple VS.NET 2003 VB program to delete files and directories on my hard drive. If the directory is read only, how do i change it's attribute so that i can delete it ? Here is some of my code. It does not error out, it just does not delete the directories. Any help would be gratefully appreciated even ideas on another way to do this.
0
2724
by: jj | last post by:
How do you programmatically change a "windows Service account" from Local system to Network or Local service by providing username and password? Thanks
6
15311
by: Andrew Jocelyn | last post by:
Hi How do I programmatically change (read/write) the values in this app.config file at runtime? Specifically I want to change the client endpoint address but it would be nice to change other values too. I thought this is what ServiceHost is for but is seems way more complicated to use for what I'm trying to do. <system.serviceModel> <bindings>
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10311
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8967
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.