On Wed, Jan 20, 2016 at 02:52:20AM -0800, Patrice wrote:
> Hello,
> 
> I followed what is describe in the docs here 
> : 
> https://docs.djangoproject.com/en/1.9/topics/testing/tools/#management-commands
> but all I got is an empty string in my *out.getvalue()*.
> 
> From what I understand from  Django code here 
> <https://github.com/django/django/blob/master/django/core/management/base.py#L339>,
>  
> it does not capture the output (ie: sys.stdout.write("blah blah")) but the 
> *return 
> value *of my command. It doesn't make sense to me, there's no point 
> returning a value in a management command.
> 
> Am I missing something? Is the documentation wrong or is it a bug ?

Hi Patrice,

Returning a value from a management command's ``handle`` method is
documented [1], though it might only be useful in very specific
situations (namely, when your management command produces SQL code).

The problem you're facing is that your management command writes
directly to ``sys.stdout`` instead of ``self.stdout`` as indicated in
the docs [2]. If you change your management command to use
``self.stdout``, it should work as you expect.

Good luck,

Michal


[1]: 
https://docs.djangoproject.com/en/1.9/howto/custom-management-commands/#django.core.management.BaseCommand.handle
[2]: 
https://docs.djangoproject.com/en/1.9/howto/custom-management-commands/#management-commands-output

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20160120111908.GE20308%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: Digital signature

Reply via email to