差異處
這裏顯示兩個版本的差異處。
python:mixed:run_script_at_same_python_path [2016/08/18 16:58] 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 ====== | ||
- | <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> |