Skip to content

Commit 18a54ab

Browse files
authored
Merge pull request #16 from tjesser-ucdavis-edu/subprocess_module
Change os.system(...) to subprocess.run(...)
2 parents ed98f76 + 357ce9e commit 18a54ab

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pytest/test_sw4.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Arguments:
44
# -h: help, -v: verbose mode -l testing level, -m mpi-tasks, -d sw4-exe-dir
55

6-
import os, sys, argparse
6+
import os, sys, argparse, subprocess
77

88
#----(Currently not used)--------------------------------------------
99
def run_checks(checks):
@@ -198,14 +198,28 @@ def main_test(sw4_exe_dir="optimize", testing_level=0, mpi_tasks=0, verbose=Fals
198198
#print('local_dir = ', local_dir)
199199

200200
# pipe stdout and stderr to a temporary file
201-
run_cmd = sw4_mpi_run + ' ' + sw4_input_file + ' >& ' + sw4_stdout_file
201+
run_cmd = mpirun_cmd.split() + [
202+
sw4_exe,
203+
sw4_input_file
204+
]
205+
206+
sw4_stdout_file = open(case_dir + '.out', 'wt')
207+
sw4_stderr_file = open(case_dir + '.err', 'wt')
202208

203209
# run sw4
204210
run_dir = os.getcwd()
205211
#print('Running sw4 from directory:', run_dir)
206-
status = os.system(run_cmd)
207-
if status!=0:
208-
print('ERROR: Test', test_case, ': sw4 returned non-zero exit status=', status, 'aborting test')
212+
status = subprocess.run(
213+
run_cmd,
214+
stdout=sw4_stdout_file,
215+
stderr=sw4_stderr_file,
216+
)
217+
218+
sw4_stdout_file.close()
219+
sw4_stderr_file.close()
220+
221+
if status.returncode!=0:
222+
print('ERROR: Test', test_case, ': sw4 returned non-zero exit status=', status.returncode, 'aborting test')
209223
print('run_cmd=', run_cmd)
210224
print("DID YOU USE THE CORRECT SW4 EXECUTABLE? (SPECIFY DIRECTORY WITH -d OPTION)")
211225
return False # bail out

0 commit comments

Comments
 (0)