第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

子流程更改目錄

子流程更改目錄

犯罪嫌疑人X 2019-10-10 16:40:44
我想在子目錄/超級目錄中執(zhí)行腳本(我首先需要在此子目錄/超級目錄中)。我無法subprocess進(jìn)入子目錄:tducin@localhost:~/Projekty/tests/ve$ pythonPython 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import subprocess>>> import os>>> os.getcwd()'/home/tducin/Projekty/tests/ve'>>> subprocess.call(['cd ..'])Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/lib/python2.7/subprocess.py", line 524, in call    return Popen(*popenargs, **kwargs).wait()  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__    errread, errwrite)  File "/usr/lib/python2.7/subprocess.py", line 1308, in _execute_child    raise child_exceptionOSError: [Errno 2] No such file or directoryPython拋出OSError,我不知道為什么。無論
查看完整描述

3 回答

?
慕姐4208626

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個贊

要your_command在不同目錄中作為子進(jìn)程運(yùn)行cwd,請按照@wim的答案中的建議傳遞參數(shù):


import subprocess


subprocess.check_call(['your_command', 'arg 1', 'arg 2'], cwd=working_dir)

子進(jìn)程無法更改其父級的工作目錄(通常是)。cd ..使用子進(jìn)程在子shell進(jìn)程中運(yùn)行不會更改父Python腳本的工作目錄,即@glglgl的答案中的代碼示例錯誤。cd是內(nèi)置的shell(不是單獨(dú)的可執(zhí)行文件),它只能在同一過程中更改目錄。


查看完整回答
反對 回復(fù) 2019-10-10
  • 3 回答
  • 0 關(guān)注
  • 584 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號