Skip to content

Commit 9051498

Browse files
authored
Correct output redirection
1 parent 6876af9 commit 9051498

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/pyscipopt/scip.pxi

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cimport cython
1212
from cpython cimport Py_INCREF, Py_DECREF
1313
from cpython.pycapsule cimport PyCapsule_New, PyCapsule_IsValid, PyCapsule_GetPointer
1414
from libc.stdlib cimport malloc, free
15-
from libc.stdio cimport fdopen, fclose
15+
from libc.stdio cimport stdout, stderr, fdopen, fputs, fflush, fclose
1616
from posix.stdio cimport fileno
1717

1818
from collections.abc import Iterable
@@ -1851,10 +1851,22 @@ cdef class Constraint:
18511851

18521852

18531853
cdef void relayMessage(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *msg) noexcept:
1854-
sys.stdout.write(msg.decode('UTF-8'))
1854+
if file is stdout:
1855+
sys.stdout.write(msg.decode('UTF-8'))
1856+
elif file is stderr:
1857+
sys.stderr.write(msg.decode('UTF-8'))
1858+
else:
1859+
if msg is not NULL:
1860+
fputs(msg, file)
1861+
fflush(file)
18551862

18561863
cdef void relayErrorMessage(void *messagehdlr, FILE *file, const char *msg) noexcept:
1857-
sys.stderr.write(msg.decode('UTF-8'))
1864+
if file is NULL:
1865+
sys.stderr.write(msg.decode('UTF-8'))
1866+
else:
1867+
if msg is not NULL:
1868+
fputs(msg, file)
1869+
fflush(file)
18581870

18591871
# - remove create(), includeDefaultPlugins(), createProbBasic() methods
18601872
# - replace free() by "destructor"

0 commit comments

Comments
 (0)