Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > command prompt change dir

Reply
Thread Tools

command prompt change dir

 
 
Peter Vestergaard
Guest
Posts: n/a
 
      07-11-2003
Hi
Probably a simple question but I have not been able to find out how:
I want my python script to generate a path based on some simple lookups and
then change my path so that when the script exits my command prompt (from
which I launched the script) is standing at this path. The path already
exists.
I have tried chdir(path), system('cd '+path) and many others but none
changes my actual path.
Hope anyone can help
Regards, Peter Vestergaard


 
Reply With Quote
 
 
 
 
Tim Roberts
Guest
Posts: n/a
 
      07-13-2003
"Peter Vestergaard" <(E-Mail Removed)> wrote:
>
>Probably a simple question but I have not been able to find out how:
>I want my python script to generate a path based on some simple lookups and
>then change my path so that when the script exits my command prompt (from
>which I launched the script) is standing at this path. The path already
>exists.
>I have tried chdir(path), system('cd '+path) and many others but none
>changes my actual path.


How many times do you need to do this? You can set the PATH environment
variable and spawn off a new copy of cmd.exe, which will inherit your
modified environment.
--
- Tim Roberts, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?I=F1igo?= Serna
Guest
Posts: n/a
 
      07-13-2003
Hello,

I think this is the solution midnight commander uses.

In lfm [1], I use something similar: I've created next shell function in
/etc/bashrc:

lfm ()
{
/usr/bin/lfm $*;
LFMPATHFILE=/tmp/lfm-$$.path;
cd "`cat $LFMPATHFILE`";
rm -f -f $LFMPATHFILE
}

Before exit, the program writes the directory into a temporal file
/tmp/lfm-pid.path, where pid is the process id of lfm, then change the
directory.

I hope this helps,
Iņigo

[1] http://www.terra.es/personal9/inigoserna/lfm


El vie, 11-07-2003 a las 10:28, Martin Franklin escribiķ:
> On Friday 11 July 2003 07:39, Peter Vestergaard wrote:
> > Hi
> > Probably a simple question but I have not been able to find out how:
> > I want my python script to generate a path based on some simple lookups and
> > then change my path so that when the script exits my command prompt (from
> > which I launched the script) is standing at this path. The path already
> > exists.
> > I have tried chdir(path), system('cd '+path) and many others but none
> > changes my actual path.
> > Hope anyone can help
> > Regards, Peter Vestergaard

>
> I don't think it is possible to change the path of the calling program (in
> this case the command prompt you use to start the python script....)
> However you could use a shell trick to kind of do what you want:-
>
>
> #!/usr/local/bin/python
> # ChangePath script
> # invoke from command line like so:
> # cd `ChangePath.py`
> #
>
> # simple lookup...
> path = "/usr/oracle/"
> print path
>
>
> Invoke the above from your command line (xterm or whatever...)
>
> cd `ChangePath.py`
>
> I have only tested this on Linux + bash and I would guess this would not work
> on Windows...
>
>
> Regards
> Martin



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQA/Eb1sfN63/+cBjZoRAryDAKCW4L6zS1qOUGbz5PEI8xu3Bqp49gCg4fD/
iw5OXyHnvFnS0N27G1vUeYQ=
=JuiU
-----END PGP SIGNATURE-----

 
Reply With Quote
 
Peter Vestergaard
Guest
Posts: n/a
 
      07-14-2003
Hi
The idea of a temporary file seemed a bit ugly to me, but at second thought
it ain't that bad, and now I have made a solution with 1 bat file (call
python, call temp.bat, del temp.bat), 1 python file and 1 temporary bat
file, which works exactly as I wanted it.
Thanks for all the suggestions!
/Peter

"Iņigo Serna" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...


 
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
javac command not working in command prompt chrisdude911 Java 10 03-10-2009 09:55 AM
How can I implement cd (change dir) command in Ruby? Sam Kong Ruby 1 06-21-2007 06:04 PM
Behaviour of Dir.glob("**/b") and Dir.glob("*/b") for symlinks Matthew Denner Ruby 1 08-04-2006 03:42 PM
Access Denied when i type command at command prompt calvin MCDST 0 03-08-2006 06:33 AM
Sub Dir, Virtual dir, what do I use? =?Utf-8?B?UnVkeQ==?= ASP .Net 0 06-12-2005 08:25 PM



Advertisments