@@ -992,25 +992,31 @@ def macro(self, parameter_s=''):
992992 print macro ,
993993
994994 @magic_arguments .magic_arguments ()
995- @magic_arguments .argument ('-o' , '--out' , type = str ,
996- help = """The name of the variable in which to store stdout
995+ @magic_arguments .argument ('output' , type = str , default = '' , nargs = '?' ,
996+ help = """The name of the variable in which to store output.
997+ This is a utils.io.CapturedIO object with stdout/err attributes
998+ for the text of the captured output.
997999
998- If unspecified: stdout is discarded
999- """
1000- )
1001- @magic_arguments .argument ('-e' , '--err' , type = str ,
1002- help = """The name of the variable in which to store stderr
1000+ CapturedOutput also has a show() method for displaying the output,
1001+ and __call__ as well, so you can use that to quickly display the
1002+ output.
10031003
1004- If unspecified: stderr is discarded
1004+ If unspecified, captured output is discarded.
10051005 """
10061006 )
1007+ @magic_arguments .argument ('--no-stderr' , action = "store_true" ,
1008+ help = """Don't capture stderr."""
1009+ )
1010+ @magic_arguments .argument ('--no-stdout' , action = "store_true" ,
1011+ help = """Don't capture stdout."""
1012+ )
10071013 @cell_magic
10081014 def capture (self , line , cell ):
10091015 """run the cell, capturing stdout/err"""
10101016 args = magic_arguments .parse_argstring (self .capture , line )
1011- with capture_output () as io :
1017+ out = not args .no_stdout
1018+ err = not args .no_stderr
1019+ with capture_output (out , err ) as io :
10121020 self .shell .run_cell (cell )
1013- if args .out :
1014- self .shell .user_ns [args .out ] = io .stdout
1015- if args .err :
1016- self .shell .user_ns [args .err ] = io .stderr
1021+ if args .output :
1022+ self .shell .user_ns [args .output ] = io
0 commit comments