【发布时间】:2015-10-05 14:09:42
【问题描述】:
我正在尝试从 Python 脚本更改我的终端目录。程序成功执行,但我终端中的目录没有改变。这是程序。
os
path = "/home/najeeb/Desktop/project/scan"
r = os.getcwd()
print "\n Current working directery is %s \n" % r
os.chdir(path)
retval = os.getcwd()
print "Directery changes successfull %s \n" % retval
【问题讨论】:
-
系统上的每个程序都有自己的Current-Working-Directory,子进程不能更改其父进程的工作目录。在您的示例中,命令行外壳程序是一个调用
python以执行您的脚本的程序。您的脚本的范围仅限于python程序。
标签: python ubuntu subprocess python-os