88import csv
99import sys
1010import tomllib
11+ import shlex
1112import subprocess
1213from itertools import islice
1314import numpy as np
@@ -64,19 +65,22 @@ def check_flow(dic, in_file):
6465 "See the pycopm documentation.\n "
6566 )
6667 sys .exit ()
67- flowtoml = subprocess .call (
68- dic ["flowpth" ].strip (),
69- shell = True ,
70- stderr = subprocess .STDOUT ,
71- stdout = subprocess .DEVNULL ,
72- )
73- flowflag = subprocess .call (
74- dic ["flowflag" ],
75- shell = True ,
76- stderr = subprocess .STDOUT ,
77- stdout = subprocess .DEVNULL ,
78- )
79- if flowtoml != 1 and flowflag != 1 :
68+
69+ cmd1 = shlex .split (dic ["flowpth" ].strip ()) + ["-h" ]
70+ cmd2 = shlex .split (dic ["flowflag" ]) + ["-h" ]
71+
72+ def run (cmd ):
73+ try :
74+ return subprocess .run (
75+ cmd , stdout = subprocess .DEVNULL , stderr = subprocess .STDOUT , check = False
76+ ).returncode
77+ except FileNotFoundError :
78+ return None
79+
80+ flowtoml = run (cmd1 )
81+ flowflag = run (cmd2 )
82+
83+ if not (flowtoml == 0 or flowflag == 0 ):
8084 print (
8185 f"\n The OPM flow executable '{ dic ['flowpth' ].strip ()} ' is not found; "
8286 "try to install it following the pycopm documentation.\n If it was "
@@ -85,14 +89,15 @@ def check_flow(dic, in_file):
8589 "(e.g., flow = '/home/pycopm/build/opm-simulators/bin/flow'),\n "
8690 "or using the command flag -f or --flow.\n "
8791 )
88- sys .exit ()
89- if flowtoml != 1 :
90- dic ["flow" ] = dic ["flow" ].split ()
91- for i , value in enumerate (dic ["flow" ]):
92+ sys .exit (1 )
93+
94+ if flowtoml == 0 :
95+ parts = shlex .split (dic ["flow" ])
96+ for i , value in enumerate (parts ):
9297 if "flow" in value :
93- dic [ "flow" ] [i ] = dic ["flowflag" ]
98+ parts [i ] = dic ["flowflag" ]
9499 break
95- dic ["flow" ] = " " .join (dic [ "flow" ] )
100+ dic ["flow" ] = " " .join (parts )
96101
97102
98103def read_reference (dic ):
0 commit comments