Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Changing a shell's current directory with python

Reply
Thread Tools

Re: Changing a shell's current directory with python

 
 
Peter Hansen
Guest
Posts: n/a
 
      12-19-2005
Andy B. wrote:
> 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?


As you've heard, you can't get there from here. In fact, even just
wrapping with a shell script likely won't be enough, unless you are
willing to "source" the script every time you run it. The only way I
know of (and I'd be happy to hear alternatives) to do this in a
_transparent_ manner is to combine an alias (which uses "source" for
you) with a wrapper script _and_ to have that wrapper script read from
some place (stdout or a temporary file or ?) to which the Python script
can communicate the desired new environment variables and/or current
directory.

-Peter

 
Reply With Quote
 
 
 
 
Mike Meyer
Guest
Posts: n/a
 
      12-19-2005
Peter Hansen <(E-Mail Removed)> writes:
> Andy B. wrote:
>> 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?

> As you've heard, you can't get there from here. In fact, even just
> wrapping with a shell script likely won't be enough, unless you are
> willing to "source" the script every time you run it. The only way I
> know of (and I'd be happy to hear alternatives) to do this in a
> _transparent_ manner is to combine an alias (which uses "source" for
> you) with a wrapper script _and_ to have that wrapper script read from
> some place (stdout or a temporary file or ?) to which the Python
> script can communicate the desired new environment variables and/or
> current directory.


The (slightly cleaner) alias approach is to have the alias eval the
results of invoking your python script, and have the python print the
appropriate cd command to standard output.

<mike
--
Mike Meyer <(E-Mail Removed)> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing a shell's current directory with python Andy B. Python 4 01-30-2011 05:16 AM
Changing the current directory (full post) vsoler Python 8 11-16-2009 10:54 PM
Changing the current directory vsoler Python 0 11-15-2009 11:59 AM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
Changing the program's current directory. Dave Rudolf Java 2 01-17-2007 12:42 AM



Advertisments