Change working directory in shell with a python script

前端 未结 5 1315
遇见更好的自我
遇见更好的自我 2020-12-06 01:16

I want to implement a userland command that will take one of its arguments (path) and change the directory to that dir. After the program completion I would like the shell t

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 01:58

    As codaddict writes, what happens in your sub-shell does not affect the parent shell. However, if your goal is present the user with a shell in a different directory, you could always have Python use os.chdir to change the sub-shell's working directory and then launch a new shell from Python. This will not change the working directory of the original shell, but will leave the user with one in a different directory.

提交回复
热议问题