差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

python:mixed:run_script_at_same_python_path [2016/08/18 22:01]
tony
python:mixed:run_script_at_same_python_path [2023/06/25 09:48]
行 1: 行 1:
-{{tag>​python}} 
-====== Run a script that is related to the python file path ====== 
-===== Problem ===== 
-程式目標為透過Python去呼叫相同目錄的shellscript。 
-===== How to? ===== 
-程式內容主要為:​ 
-  - 取得python相同目錄的script路徑。 
-  - 賦予此script執行權限。 
-  - 執行script。 
-<code python> 
-import os 
-import stat 
-from os.path import dirname, abspath, join 
  
-def runCollectPrograme():​ 
- mod_dir = dirname(__file__) 
- collect_script = abspath(join(mod_dir,​ '​collect.sh'​)) 
- 
- print "Run script: %s" % collect_script 
- 
- st = os.stat(collect_script) 
- os.chmod(collect_script,​ st.st_mode|stat.S_IEXEC) 
- os.system(collect_script)  
-</​code>​ 
- 
- 
-=====    ===== 
----- 
-\\ 
-~~DISQUS~~