0

What can I put in a python script that will change the shell directory when I run it. For example when I run:

c:\users\myname> python myscript.py

After the script run I get the prompt, for example:

c:\users\myname\desktop>
SethMMorton
  • 45,752
  • 12
  • 65
  • 86
user24312
  • 73
  • 8
  • 4
    Nothing :( Python will be run in a subshell and cannot affect the state of the calling shell. – SethMMorton Mar 09 '17 at 00:24
  • Is it possible at least to kill the shell that I called the script from? This way I would open another shell and kill the previous one. – user24312 Mar 09 '17 at 00:29
  • Could you explain more about what you are trying to use this for? – Harald Nordgren Mar 09 '17 at 00:34
  • The Python script needs to start a new shell process after it changes the directory. Use the `subprocess` library to do this. – Barmar Mar 09 '17 at 00:41
  • How can I do that? – user24312 Mar 09 '17 at 00:48
  • is [this](http://stackoverflow.com/questions/14894993/running-windows-shell-commands-with-python) what you're referring to? You can run shell command to cd into the directory you want? – Haiz Mar 09 '17 at 01:28
  • This is my ideia: made a script to manage my study. There is a lot of ebooks I what to study. Each ebook have its directory. If there's a new book I want to study I just: – user24312 Mar 09 '17 at 14:09
  • This is my ideia: made a script to manage my study. There is a lot of ebooks I what to study. Each ebook have its directory. If there's a new book I want to study I just: `cd book_dir` then I run `study.py --manage book.pdf`. This adds the book to a database and keeps track of the file directory. When I don't know what I want to study I just run: `study.py` and the script opens one of the books in its database. But I also want it to put the command line in the book directory. I'm on windows 7 using python 3.5 – user24312 Mar 09 '17 at 14:19

0 Answers0