MCPcopy Index your code
hub / github.com/ipython/ipython / sc

Method sc

IPython/core/magics/osm.py:566–678  ·  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

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

Callers

nothing calls this directly

Calls 3

parse_optionsMethod · 0.80
getoutputMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected