我想出了這個(gè)代碼: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)但是當(dāng)我運(yùn)行它并輸入時(shí),cd ..我得到:D:\Documents\Programmed\DesktopUnsorted>我不想要這個(gè),因?yàn)槲蚁胍龅氖牵篋:\Documents\Programmed\DesktopUnsorted>編輯我也已經(jīng)嘗試過(guò): new_location = new_location.replace(r'\n','')但它不會(huì)改變?nèi)魏螙|西
在與子進(jìn)程輸出相同的行上打印一些東西
慕田峪9158850
2021-09-11 17:42:15