動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
Python 3.6.0 on virtualenv
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Python 2.6.6を使用。
やりたいこと
- CODE_171003/test_getdir_171003.py
- CODE_171003/test_hello_171003_exec
CODE_171003より一つ上のディレクトリからtest_getdir_171003.pyを実行し、そのPython script内でbash script(test_hello_171003_exec)を実行したい。
参考
ディレクトリを探す方法は以下を参考にした。
https://stackoverflow.com/questions/4934806/how-can-i-find-scripts-directory-with-python
code
test_hello_171003_exec
# !/usr/bin/env bash
echo "zabuuun"
test_hello_171003_execにはchmod +x
しておく。
test_getdir_171003.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import subprocess as sb
# on python2.6.6
# coding rule: PEP8
def invoke_script(ascript):
#scd: script directory
scd = os.path.dirname(os.path.realpath(__file__))
acmd = scd + "/" + ascript
sb.call(acmd.split())
invoke_script("test_hello_171003_exec")
run
$ python CODE_171003/test_getdir_171003.py
zabuuun