473,396 Members | 1,683 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,396 software developers and data experts.

command prompt change dir

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
Jul 18 '05 #1
3 7255
"Peter Vestergaard" <po*****@hotmail.com> 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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2
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 lookupsand
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-----

Jul 18 '05 #3
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" <in********@terra.es> wrote in message
news:ma**********************************@python.o rg...
Jul 18 '05 #4

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

Similar topics

2
by: Hank | last post by:
Hi, does anyone know how to change the foreground color of the command prompt through python? For example if i was printing out an error message, I would like it to be red where the normal...
2
by: WStoreyII | last post by:
how do i change the default directory and prompt fo the the .net command prompt for example when i load it i wish the directory to already be desktop and the prompt to be Cmd: thanks ...
2
by: Robert Blackwell | last post by:
Is there a way to change the default directory of the command prompt? Currently, when I go run>cmd.. it starts in c:\documents and settings\my username Same with if I use the vs.net cmd...
4
by: glenn | last post by:
I keep reading all sorts of books on VS that keep telling me to click on Tools/Visual Studio Command prompt to run this program or that program. However, I do not have such a menu choice. Where is...
1
by: Jay Feldman | last post by:
I've seen some messages about the screen flashing black for a few moments when executing a program in vb.net this may be because the command prompt settings were changed. when the command prompt...
8
by: 4.spam | last post by:
Hello. WinXP, db2 v8.2.7 When I use UPDATE COMMAND OPTION USING <any_switchON(or OFF) it seems that this command has absolutely no effect on these switches since command LIST COMMAND...
4
by: =?Utf-8?B?WUlndWNoaQ==?= | last post by:
Hi , I want to run a batch file from the c# code. Every time i run the batch file command prompt is displayed. I do not want to show this command prompt. Is there any way to suppress the...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
4
by: bkamrani | last post by:
Hi, This is a basic problem, but I want to print help content in a Command Prompt in WinXP and scrolling back to see the first lines. If I start a command prompt and run python, and then for...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.