我想出了这个代码:import os, subprocess, syslocation = os.path.dirname(os.path.realpath(__file__))file = os.path.basename(__file__)#print location # + r'\' + fileuser_in = raw_input(location + '>')if user_in == 'cd ..': proc = subprocess.Popen('cd .. && cd', shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin= subprocess.PIPE) new_location = proc.stdout.read() + proc.stderr.read() + '>' #new_location = str(new_location) + '>' new_location = new_location.replace(r'\r','') new_location = new_location.replace(' ','') print new_location #new_user_in = raw_input(str(new_location) + '>') #subprocess.Popen('cd .. && ' + new_user_in, shell=True)但是当我运行它并输入时,cd ..我得到:D:\Documents\Programmed\DesktopUnsorted>我不想要这个,因为我想要它做的是:D:\Documents\Programmed\DesktopUnsorted>编辑我也已经尝试过: new_location = new_location.replace(r'\n','')但它不会改变任何东西
添加回答
举报
0/150
提交
取消