Thank you. Now I guess I'll work on figuring out *where* it was redirected.

But the "dunder" version of sys.stdout is an excellent clue -- I did not
know about that, and bonus gratitude points for giving me a new word to use.

 -Tom

On Sat, Dec 5, 2020 at 9:06 AM Shaheed Haque <[email protected]> wrote:

> I would hazard a guess that Django has already redirected stderr and or
> stdout before your code gets to run.
>
> I recommend that you stop your code in the debugger just *before* you try
> your redirection and look at the state of sys.stderr and sys.stdout. Also,
> I'm not sure if you are aware of the dunder versions of these (see
> https://docs.python.org/3/library/sys.html)? Comparing sys.stdout with
> sys.__stdout__ might reveal interesting results for example.
>
> Once you know what Django has already done, I expect you will be able to
> progress.
>
> On Sat, 5 Dec 2020, 13:18 Tom Sgouros, <[email protected]> wrote:
>
>> Matlab is the native language of the group for which I am building this
>> interface. It is for access to ocean sensor data, and it's being done this
>> way so the scientists whose sensors they are can use a significant body of
>> legacy code in their analyses. (Though I was planning to sneak in an option
>> to use python scripts because that's what I prefer.)
>>
>> But the fact remains that I have no trouble capturing stdout when I run
>> this python on the command line and it doesn't work when I run it as part
>> of a Django views.py and I don't where to begin trying to understand why
>> not.
>>
>>  -Tom
>>
>> On Fri, Dec 4, 2020 at 3:33 PM Kris A. Stern <[email protected]>
>> wrote:
>>
>>> Why not try something Python based instead which is also free. What kind
>>> of functionality are you looking for? Are you planning to plot, if so you
>>> could try numpy, scipy, and matplotlib.
>>>
>>> On Sat, 5 Dec 2020 at 02:02, Tom Sgouros <[email protected]> wrote:
>>>
>>>> Anybody have any random thoughts about this? I have run out of ideas to
>>>> test.
>>>>
>>>> Thank you,
>>>>
>>>>  -Tom
>>>>
>>>> On Wed, Dec 2, 2020 at 10:32 PM Tom Sgouros <[email protected]> wrote:
>>>>
>>>>> Hello all:
>>>>>
>>>>> I have a Django application that dispatches processing to a matlab
>>>>> script using exec. How can I capture the stdout and stderr of the script's
>>>>> execution?
>>>>>
>>>>> Outside of Django, this works for a dumb matlab script called tt that
>>>>> just prints a message:
>>>>>
>>>>> >>> import matlab.engine, StringIO
>>>>> >>> eng = matlab.engine.start_matlab()
>>>>> >>> out = StringIO.StringIO()
>>>>> >>> err = StringIO.StringIO()
>>>>> >>> exec('eng.tt(25, stdout=out, stderr=err)')
>>>>> >>> out.getvalue()
>>>>> "This is a disp command.\n\nret =\n\n '25\n\n"
>>>>>
>>>>> Inside a Django method, the exec seems to function properly, but the
>>>>> out and err variables remain empty. Where's my output? Did the logging
>>>>> system snatch it? I assume I'm missing something obvious here but any
>>>>> pointers would be welcome.
>>>>>
>>>>> Thank you,
>>>>>
>>>>>  -Tom
>>>>>
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/35b264b3-f793-4131-a6e4-700e51aebbfan%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/django-users/35b264b3-f793-4131-a6e4-700e51aebbfan%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAFUviqs6XXxfzOqQ4uCnVBEo2cN%2BbMMPHPEO-wtbxPVa94PtHw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAFUviqs6XXxfzOqQ4uCnVBEo2cN%2BbMMPHPEO-wtbxPVa94PtHw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAMxZ8Sm7avV%3Df664b%3D8hYQWgAUwvpL%2BLVZV%3D31Hy21B2xeSDtA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAMxZ8Sm7avV%3Df664b%3D8hYQWgAUwvpL%2BLVZV%3D31Hy21B2xeSDtA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAFUviqvvOZUorVSmT1DSe_GO53_UEntvshiEzLxtUCAg%2BRFcPw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAFUviqvvOZUorVSmT1DSe_GO53_UEntvshiEzLxtUCAg%2BRFcPw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHAc2jeKu4JLknHV_WCZzMZHaOGUP8P8hsWOjpOiFwdDpkYk2A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAHAc2jeKu4JLknHV_WCZzMZHaOGUP8P8hsWOjpOiFwdDpkYk2A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFUviqvXn91RUue7M6es7LTNGYZ7pYk4mQrd3CmtCHeLQBt6gQ%40mail.gmail.com.

Reply via email to