473,395 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Changing a shell's current directory with python

I've got a python utility that I want to change my shell's current
directory based on criteria it finds. I've scoured google and the
python cookbook and can't seem to figure out if this is even possible.
So far, all my attempts have changed the current python session only.
Am I going to have to wrap this in a shell script?

% pwd
/var/tmp
% myutil.py
# do some stuff and cd to '/var/log'
% pwd
/var/log

Many thanks,

-A
Dec 19 '05 #1
2 2679
irIl 2005-12-18, Andy B. <ab******@gmail.com> ha scritto:
I've got a python utility that I want to change my shell's current
directory based on criteria it finds. I've scoured google and the
python cookbook and can't seem to figure out if this is even possible.
So far, all my attempts have changed the current python session only.
Am I going to have to wrap this in a shell script?

% pwd
/var/tmp
% myutil.py
# do some stuff and cd to '/var/log'
% pwd
/var/log


Just look in the library:

import os
os.chdir("path")
--
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
Dec 19 '05 #2
Many thanks for the sanity check. Just wanted to check with the gurus
before heading down another path.

-A
On 12/18/05, Dennis Lee Bieber <wl*****@ix.netcom.com> wrote:
On Sun, 18 Dec 2005 15:53:11 -0800, "Andy B." <ab******@gmail.com>
declaimed the following in comp.lang.python:
I've got a python utility that I want to change my shell's current
directory based on criteria it finds. I've scoured google and the
python cookbook and can't seem to figure out if this is even possible.
So far, all my attempts have changed the current python session only.
Am I going to have to wrap this in a shell script?


That's about all you will be able to achieve... the inheritance goes
downwards: shell -> program(python, etc.) -> spawned processes
(os.system, etc.)... Changes at one level are only picked up by things
started after that change, and started from that level.
--
> ================================================== ============ <
> wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wu******@dm.net | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

--
http://mail.python.org/mailman/listinfo/python-list

Dec 19 '05 #3

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

Similar topics

2
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package...
8
by: Neale | last post by:
In a python program, I want to do a Unix directory list and then append selected files to each other which, as you know, is just "cat filename2 >> filename1." How do I escape into the shell and...
9
by: Jeff Wagner | last post by:
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to getting started? Thanks, Jeff
5
by: skip | last post by:
A simple script like the one below lets me jump through a directory structure. However, if I run it from /this/directory and within it to go to /a/totally/different/directory... I'm still...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
3
by: Chris Mellon | last post by:
This appears to be a change in behavior from Python 2.4 to Python 2.5, which I can't find documented anywhere. It may be windows only, or related to Windows behavior. In 2.4, the current...
3
by: tedpottel | last post by:
Hi, I'm trying to write a ftp in python to send files to my webserverr. Curtly I will change the directory to the folder name, down load the file, then do a chnag dir ..\ to go back to the root...
1
by: Svenn Are Bjerkem | last post by:
Hi, as a user on a linux system I am member of the groups "users" and "design" with users as my default group. To controll the accessibility of some parts of the file system, creation of files and...
3
by: Max Vit | last post by:
I have come across a strange issue whilst trying to use a shell command call from Access and have spent some time trying to figure this out but can't find the cause as yet. The issue is: I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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,...

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.