MCPcopy Create free account
hub / github.com/ipython/ipython / sc

Method sc

IPython/core/magics/osm.py:567–679  ·  view source on GitHub ↗

Shell capture - run shell command and capture output (DEPRECATED use !). DEPRECATED. Suboptimal, retained for backwards compatibility. You should use the form 'var = !command' instead. Example: "%sc -l myfiles = ls ~" should now be written as "myfiles = !ls ~"

(self, parameter_s='')

Source from the content-addressed store, hash-verified

565 @skip_doctest
566 @line_magic
567 def sc(self, parameter_s=''):
568 """Shell capture - run shell command and capture output (DEPRECATED use !).
569
570 DEPRECATED. Suboptimal, retained for backwards compatibility.
571
572 You should use the form 'var = !command' instead. Example:
573
574 "%sc -l myfiles = ls ~" should now be written as
575
576 "myfiles = !ls ~"
577
578 myfiles.s, myfiles.l and myfiles.n still apply as documented
579 below.
580
581 --
582 %sc [options] varname=command
583
584 IPython will run the given command using commands.getoutput(), and
585 will then update the user's interactive namespace with a variable
586 called varname, containing the value of the call. Your command can
587 contain shell wildcards, pipes, etc.
588
589 The '=' sign in the syntax is mandatory, and the variable name you
590 supply must follow Python's standard conventions for valid names.
591
592 (A special format without variable name exists for internal use)
593
594 Options:
595
596 -l: list output. Split the output on newlines into a list before
597 assigning it to the given variable. By default the output is stored
598 as a single string.
599
600 -v: verbose. Print the contents of the variable.
601
602 In most cases you should not need to split as a list, because the
603 returned value is a special type of string which can automatically
604 provide its contents either as a list (split on newlines) or as a
605 space-separated string. These are convenient, respectively, either
606 for sequential processing or to be passed to a shell command.
607
608 For example::
609
610 # Capture into variable a
611 In [1]: sc a=ls *py
612
613 # a is a string with embedded newlines
614 In [2]: a
615 Out[2]: 'setup.py\\nwin32_manual_post_install.py'
616
617 # which can be seen as a list:
618 In [3]: a.l
619 Out[3]: ['setup.py', 'win32_manual_post_install.py']
620
621 # or as a whitespace-separated string:
622 In [4]: a.s
623 Out[4]: 'setup.py win32_manual_post_install.py'
624

Callers

nothing calls this directly

Calls 3

parse_optionsMethod · 0.80
getoutputMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected