Skip to content

Commit 7fd956a

Browse files
committed
[ModelicaSystem.simulate] simplify usage of subprocess.Popen()
* difference between win and linux is only in the definition of my_env
1 parent cc44f53 commit 7fd956a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

OMPython/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,15 +1303,15 @@ def simulate(self, resultfile=None, simflags=None, verbose=True): # 11
13031303
dllPath = pkgpath_wver + os.pathsep + dllPath
13041304
my_env = os.environ.copy()
13051305
my_env["PATH"] = dllPath + os.pathsep + my_env["PATH"]
1306-
if not verbose:
1307-
p = subprocess.Popen(cmd, env=my_env, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
1308-
else:
1309-
p = subprocess.Popen(cmd, env=my_env)
13101306
else:
1311-
if not verbose:
1312-
p = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
1313-
else:
1314-
p = subprocess.Popen(cmd)
1307+
my_env = None
1308+
1309+
p = subprocess.Popen(cmd, env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
1310+
stdout, stderr = p.communicate()
1311+
if stderr:
1312+
logger.warning(f"OM error: {stderr.decode('ascii')}")
1313+
if verbose and stdout:
1314+
logger.info(f"OM output:\n{stdout.decode('ascii').strip()}")
13151315
p.wait()
13161316
p.terminate()
13171317
os.chdir(currentDir)

0 commit comments

Comments
 (0)