473,766 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7281
"Peter Vestergaard" <po*****@hotmai l.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/+cBjZoRAryDAKCW 4L6zS1qOUGbz5PE I8xu3Bqp49gCg4f D/
iw5OXyHnvFnS0N2 7G1vUeYQ=
=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********@ter ra.es> wrote in message
news:ma******** *************** ***********@pyt hon.org...
Jul 18 '05 #4

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

Similar topics

2
6655
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 text color is white. Thanks
2
1947
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 WStoreyII
2
2419
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 prompt. I'd like to change it to something more specific so when I go to the cmd prompt, I don't have to navigate to a bunch of directories above, to find my
4
2532
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 this menu? thanks, glenn
1
1912
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 is set to full screen mode instead of window mode, some monitors don't seem to be able to take it. when this happened to my computer, the screen would go black (for however long the command prompt window had to appear) and the monitor (new, 17"...
8
8655
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 OPTIONS issued after that shows the same values as before issuing UPDATE
4
2583
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 command prompt. Regards, Y iguchi
7
9372
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 display the Windows form. The form is being displayed but the command only returns when the form is closed. I want the command line to return immediately, leaving the form displayed.
4
2541
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 example, it starts showing the help, which can be controlled by page or raw using Spacebar or Enter but after this ends, it seems that I can't scroll back to see again the first lines. In the Command Prompt Properties, layout tab, my Screen...
0
10168
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...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
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
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
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
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.