-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path17-Subprocess.html
95 lines (84 loc) · 56.5 KB
/
17-Subprocess.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>17-Subprocess</title>
<script type="text/javascript" src="17-Subprocess_files/MathJax.js" charset="utf-8"></script>
<script type="text/javascript">
// MathJax disabled, set as null to distingish from *missing* MathJax,
// where it will be undefined, and should prompt a dialog later.
window.mathjax_url = "mathjax/MathJax.js";
</script>
<link rel="stylesheet" href="17-Subprocess_files/jquery-wijmo.css" type="text/css">
<link rel="stylesheet" href="17-Subprocess_files/codemirror.css">
<link rel="stylesheet" href="17-Subprocess_files/markdown.css">
<link rel="stylesheet" href="17-Subprocess_files/rst.css">
<link rel="stylesheet" href="17-Subprocess_files/ipython.css">
<link rel="stylesheet" href="17-Subprocess_files/default.css">
<link rel="stylesheet" href="17-Subprocess_files/prettify.css">
<link rel="stylesheet" href="17-Subprocess_files/boilerplate.css" type="text/css">
<link rel="stylesheet" href="17-Subprocess_files/layout.css" type="text/css">
<link rel="stylesheet" href="17-Subprocess_files/base.css" type="text/css">
<link rel="stylesheet" href="17-Subprocess_files/notebook.css" type="text/css">
<link rel="stylesheet" href="17-Subprocess_files/renderedhtml.css" type="text/css">
<meta name="read_only" content="False">
<style type="text/css">#MathJax_Zoom {position: absolute; background-color: #F0F0F0; overflow: auto; display: block; z-index: 301; padding: .5em; border: 1px solid black; margin: 0; font-family: serif; font-size: 85%; font-weight: normal; font-style: normal; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; box-shadow: 5px 5px 15px #AAAAAA; -webkit-box-shadow: 5px 5px 15px #AAAAAA; -moz-box-shadow: 5px 5px 15px #AAAAAA; -khtml-box-shadow: 5px 5px 15px #AAAAAA; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_ZoomOverlay {position: absolute; left: 0; top: 0; z-index: 300; display: inline-block; width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
</style><style type="text/css">#MathJax_About {position: fixed; left: 50%; width: auto; text-align: center; border: 3px outset; padding: 1em 2em; background-color: #DDDDDD; cursor: default; font-family: message-box; font-size: 120%; font-style: normal; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -khtml-border-radius: 15px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_Menu {position: absolute; background-color: white; color: black; width: auto; padding: 5px 0px; border: 1px solid #CCCCCC; margin: 0; cursor: default; font: menu; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; -khtml-border-radius: 5px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_MenuItem {padding: 1px 2em; background: transparent}
.MathJax_MenuTitle {background-color: #CCCCCC; margin: -5px 0 0 0; text-align: center; font-style: italic; font-size: 80%; color: #444444; padding: 2px 0; overflow: hidden}
.MathJax_MenuArrow {position: absolute; right: .5em; color: #666666}
.MathJax_MenuActive .MathJax_MenuArrow {color: white}
.MathJax_MenuCheck {position: absolute; left: .7em}
.MathJax_MenuRadioCheck {position: absolute; left: .7em}
.MathJax_MenuLabel {padding: 1px 2em 3px 1.33em; font-style: italic}
.MathJax_MenuRule {border-top: 1px solid #DDDDDD; margin: 4px 3px}
.MathJax_MenuDisabled {color: GrayText}
.MathJax_MenuActive {background-color: #606872; color: white}
</style><style type="text/css">#MathJax_Message {position: fixed; left: 1px; bottom: 2px; background-color: #E6E6E6; border: 1px solid #959595; margin: 0px; padding: 2px 8px; z-index: 102; color: black; font-size: 80%; width: auto; white-space: nowrap}
#MathJax_MSIE_Frame {position: absolute; top: 0; left: 0; width: 0px; z-index: 101; border: 0px; margin: 0px; padding: 0px}
.MathJax_Error {color: #CC0000; font-style: italic}
</style><style type="text/css">@media print { body { overflow: visible !important; } }.ui-widget-content { border: 0px; }</style><style type="text/css">#MathJax_Zoom {position: absolute; background-color: #F0F0F0; overflow: auto; display: block; z-index: 301; padding: .5em; border: 1px solid black; margin: 0; font-family: serif; font-size: 85%; font-weight: normal; font-style: normal; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; box-shadow: 5px 5px 15px #AAAAAA; -webkit-box-shadow: 5px 5px 15px #AAAAAA; -moz-box-shadow: 5px 5px 15px #AAAAAA; -khtml-box-shadow: 5px 5px 15px #AAAAAA; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_ZoomOverlay {position: absolute; left: 0; top: 0; z-index: 300; display: inline-block; width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
</style><style type="text/css">#MathJax_About {position: fixed; left: 50%; width: auto; text-align: center; border: 3px outset; padding: 1em 2em; background-color: #DDDDDD; cursor: default; font-family: message-box; font-size: 120%; font-style: normal; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -khtml-border-radius: 15px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_Menu {position: absolute; background-color: white; color: black; width: auto; padding: 5px 0px; border: 1px solid #CCCCCC; margin: 0; cursor: default; font: menu; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; -khtml-border-radius: 5px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_MenuItem {padding: 1px 2em; background: transparent}
.MathJax_MenuTitle {background-color: #CCCCCC; margin: -5px 0 0 0; text-align: center; font-style: italic; font-size: 80%; color: #444444; padding: 2px 0; overflow: hidden}
.MathJax_MenuArrow {position: absolute; right: .5em; color: #666666}
.MathJax_MenuActive .MathJax_MenuArrow {color: white}
.MathJax_MenuCheck {position: absolute; left: .7em}
.MathJax_MenuRadioCheck {position: absolute; left: .7em}
.MathJax_MenuLabel {padding: 1px 2em 3px 1.33em; font-style: italic}
.MathJax_MenuRule {border-top: 1px solid #DDDDDD; margin: 4px 3px}
.MathJax_MenuDisabled {color: GrayText}
.MathJax_MenuActive {background-color: #606872; color: white}
</style><style type="text/css">#MathJax_Message {position: fixed; left: 1px; bottom: 2px; background-color: #E6E6E6; border: 1px solid #959595; margin: 0px; padding: 2px 8px; z-index: 102; color: black; font-size: 80%; width: auto; white-space: nowrap}
#MathJax_MSIE_Frame {position: absolute; top: 0; left: 0; width: 0px; z-index: 101; border: 0px; margin: 0px; padding: 0px}
.MathJax_Error {color: #CC0000; font-style: italic}
</style></head><body style="overflow: auto;"><div tabindex="2" class="cell text_cell border-box-sizing"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 1px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h1>Subprocess</h1></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [1]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>import subprocess</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-keyword">import</span><span class="cm-null"> </span><span class="cm-variable">subprocess</span></pre></div></div></div></div></div></div></div></div></div><div style="display: none;" class="output vbox"></div></div><div tabindex="2" class="cell text_cell border-box-sizing"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 8px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h2>Calling subprocesses</h2>
<p>There are several convenience methods for calling subprocesses, either using or
discarding their output:</p>
<ul>
<li><code>call()</code></li>
<li><code>check_call()</code></li>
<li><code>check_output()</code></li>
</ul></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [2]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>subprocess.call('ls')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">subprocess.call</span><span class="cm-null">(</span><span class="cm-string">'ls'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[2]:</div><div class="box_flex1 output_subarea output_text"><pre>0</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [3]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>subprocess.check_call('ls')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">subprocess.check_call</span><span class="cm-null">(</span><span class="cm-string">'ls'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[3]:</div><div class="box_flex1 output_subarea output_text"><pre>0</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [4]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>subprocess.check_output('ls')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">subprocess.check_output</span><span class="cm-null">(</span><span class="cm-string">'ls'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[4]:</div><div class="box_flex1 output_subarea output_text"><pre>'01-BasicPythonSyntax\n01-BasicPythonSyntax_files\n01-BasicPythonSyntax.html\n01-BasicPythonSyntax.ipynb\n02-Builtins\n02-Builtins_files\n02-Builtins.html\n02-Builtins.ipynb\n03-FileIO\n03-FileIO_files\n03-FileIO.html\n03-FileIO.ipynb\n04-UsingModules\n04-UsingModules_files\n04-UsingModules.html\n04-UsingModules.ipynb\n05-Strings\n05-Strings_files\n05-Strings.html\n05-Strings.ipynb\n06a-Packages\n06-Regex\n06-Regex_files\n06-Regex.html\n06-Regex.ipynb\n07-Functions\n07-Functions_files\n07-Functions.html\n07-Functions.ipynb\n08-AdvancedFunctions\n08-AdvancedFunctions_files\n08-AdvancedFunctions.html\n08-AdvancedFunctions.ipynb\n09-Logging\n09-Logging_files\n09-Logging.html\n09-Logging.ipynb\n10-OOP1\n10-OOP1_files\n10-OOP1.html\n10-OOP1.ipynb\n11-OOP2\n11-OOP2_files\n11-OOP2.html\n11-OOP2.ipynb\n12-Decorators\n12-Decorators_files\n12-Decorators.html\n12-Decorators.ipynb\n13-Generators\n13-GeneratorsAndIterators_files\n13-GeneratorsAndIterators.html\n13-GeneratorsAndIterators.ipynb\n14-ContextManagers\n14-ContextManagers_files\n14-ContextManagers.html\n14-ContextManagers.ipynb\n15-Threading\n16-Multiprocessing\n17-Subprocess\n17-Subprocess.ipynb\n18-Virtualenv\n19-Testing\n20-MoreModules.ipynb\nfabfile.py\nfabfile.pyc\nFastTrackToPython.pdf\nindex.md\nVagrantfile\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [5]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>subprocess.check_output(['ls', '-a'])</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">subprocess.check_output</span><span class="cm-null">([</span><span class="cm-string">'ls'</span><span class="cm-null">, </span><span class="cm-string">'-a'</span><span class="cm-null">])</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[5]:</div><div class="box_flex1 output_subarea output_text"><pre>'.\n..\n01-BasicPythonSyntax\n01-BasicPythonSyntax_files\n01-BasicPythonSyntax.html\n01-BasicPythonSyntax.ipynb\n02-Builtins\n02-Builtins_files\n02-Builtins.html\n02-Builtins.ipynb\n03-FileIO\n03-FileIO_files\n03-FileIO.html\n03-FileIO.ipynb\n04-UsingModules\n04-UsingModules_files\n04-UsingModules.html\n04-UsingModules.ipynb\n05-Strings\n05-Strings_files\n05-Strings.html\n05-Strings.ipynb\n06a-Packages\n06-Regex\n06-Regex_files\n06-Regex.html\n06-Regex.ipynb\n07-Functions\n07-Functions_files\n07-Functions.html\n07-Functions.ipynb\n08-AdvancedFunctions\n08-AdvancedFunctions_files\n08-AdvancedFunctions.html\n08-AdvancedFunctions.ipynb\n09-Logging\n09-Logging_files\n09-Logging.html\n09-Logging.ipynb\n10-OOP1\n10-OOP1_files\n10-OOP1.html\n10-OOP1.ipynb\n11-OOP2\n11-OOP2_files\n11-OOP2.html\n11-OOP2.ipynb\n12-Decorators\n12-Decorators_files\n12-Decorators.html\n12-Decorators.ipynb\n13-Generators\n13-GeneratorsAndIterators_files\n13-GeneratorsAndIterators.html\n13-GeneratorsAndIterators.ipynb\n14-ContextManagers\n14-ContextManagers_files\n14-ContextManagers.html\n14-ContextManagers.ipynb\n15-Threading\n16-Multiprocessing\n17-Subprocess\n17-Subprocess.ipynb\n18-Virtualenv\n19-Testing\n20-MoreModules.ipynb\nfabfile.py\nfabfile.pyc\nFastTrackToPython.pdf\n.git\nindex.md\n.vagrant\nVagrantfile\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [6]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>subprocess.call(['ls', '/directory/does/not/exist'])</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">subprocess.call</span><span class="cm-null">([</span><span class="cm-string">'ls'</span><span class="cm-null">, </span><span class="cm-string">'/directory/does/not/exist'</span><span class="cm-null">])</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[6]:</div><div class="box_flex1 output_subarea output_text"><pre>2</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [7]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 82px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span> subprocess.check_output(['ls', '-a', '/directory/does/not/exist'])</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-keyword">try</span><span class="cm-null">:</span></pre><pre><span class="cm-null"> </span><span class="cm-variable">subprocess.check_output</span><span class="cm-null">([</span><span class="cm-string">'ls'</span><span class="cm-null">, </span><span class="cm-string">'-a'</span><span class="cm-null">, </span><span class="cm-string">'/directory/does/not/exist'</span><span class="cm-null">])</span></pre><pre><span class="cm-keyword">except</span><span class="cm-null"> </span><span class="cm-variable">subprocess.CalledProcessError</span><span class="cm-null">, </span><span class="cm-variable">error</span><span class="cm-null">:</span></pre><pre><span class="cm-null"> </span><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-string">'Exception raised: %s'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-variable">error</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>Exception raised: Command '['ls', '-a', '/directory/does/not/exist']' returned non-zero exit status 2
</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [8]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 82px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span> subprocess.check_call(['ls', '-a', '/directory/does/not/exist'])</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-keyword">try</span><span class="cm-null">:</span></pre><pre><span class="cm-null"> </span><span class="cm-variable">subprocess.check_call</span><span class="cm-null">([</span><span class="cm-string">'ls'</span><span class="cm-null">, </span><span class="cm-string">'-a'</span><span class="cm-null">, </span><span class="cm-string">'/directory/does/not/exist'</span><span class="cm-null">])</span></pre><pre><span class="cm-keyword">except</span><span class="cm-null"> </span><span class="cm-variable">subprocess.CalledProcessError</span><span class="cm-null">, </span><span class="cm-variable">error</span><span class="cm-null">:</span></pre><pre><span class="cm-null"> </span><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-string">'Exception raised: %s'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-variable">error</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>Exception raised: Command '['ls', '-a', '/directory/does/not/exist']' returned non-zero exit status 2
</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [9]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>subprocess.check_output('ls -a', shell=True)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">subprocess.check_output</span><span class="cm-null">(</span><span class="cm-string">'ls -a'</span><span class="cm-null">, </span><span class="cm-variable">shell</span><span class="cm-null">=</span><span class="cm-variable">True</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[9]:</div><div class="box_flex1 output_subarea output_text"><pre>'.\n..\n01-BasicPythonSyntax\n01-BasicPythonSyntax_files\n01-BasicPythonSyntax.html\n01-BasicPythonSyntax.ipynb\n02-Builtins\n02-Builtins_files\n02-Builtins.html\n02-Builtins.ipynb\n03-FileIO\n03-FileIO_files\n03-FileIO.html\n03-FileIO.ipynb\n04-UsingModules\n04-UsingModules_files\n04-UsingModules.html\n04-UsingModules.ipynb\n05-Strings\n05-Strings_files\n05-Strings.html\n05-Strings.ipynb\n06a-Packages\n06-Regex\n06-Regex_files\n06-Regex.html\n06-Regex.ipynb\n07-Functions\n07-Functions_files\n07-Functions.html\n07-Functions.ipynb\n08-AdvancedFunctions\n08-AdvancedFunctions_files\n08-AdvancedFunctions.html\n08-AdvancedFunctions.ipynb\n09-Logging\n09-Logging_files\n09-Logging.html\n09-Logging.ipynb\n10-OOP1\n10-OOP1_files\n10-OOP1.html\n10-OOP1.ipynb\n11-OOP2\n11-OOP2_files\n11-OOP2.html\n11-OOP2.ipynb\n12-Decorators\n12-Decorators_files\n12-Decorators.html\n12-Decorators.ipynb\n13-Generators\n13-GeneratorsAndIterators_files\n13-GeneratorsAndIterators.html\n13-GeneratorsAndIterators.ipynb\n14-ContextManagers\n14-ContextManagers_files\n14-ContextManagers.html\n14-ContextManagers.ipynb\n15-Threading\n16-Multiprocessing\n17-Subprocess\n17-Subprocess.ipynb\n18-Virtualenv\n19-Testing\n20-MoreModules.ipynb\nfabfile.py\nfabfile.pyc\nFastTrackToPython.pdf\n.git\nindex.md\n.vagrant\nVagrantfile\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [10]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 82px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>subprocess.check_output(shlex.split(command_string))</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-keyword">import</span><span class="cm-null"> </span><span class="cm-variable">shlex</span></pre><pre><span class="cm-variable">command_string</span><span class="cm-null"> = </span><span class="cm-string">'ls -l -a'</span></pre><pre><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-variable">shlex.split</span><span class="cm-null">(</span><span class="cm-variable">command_string</span><span class="cm-null">)</span></pre><pre><span class="cm-variable">subprocess.check_output</span><span class="cm-null">(</span><span class="cm-variable">shlex.split</span><span class="cm-null">(</span><span class="cm-variable">command_string</span><span class="cm-null">))</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>['ls', '-l', '-a']
</pre></div></div><div class="hbox output_area"><div class="prompt output_prompt">Out[10]:</div><div class="box_flex1 output_subarea output_text"><pre>'total 2824\ndrwxr-xr-x 1 vagrant vagrant 2482 Oct 9 20:46 .\ndrwxr-xr-x 24 root root 4096 Oct 3 03:20 ..\ndrwxr-xr-x 1 vagrant vagrant 238 Oct 9 06:52 01-BasicPythonSyntax\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:14 01-BasicPythonSyntax_files\n-rw-r--r-- 1 vagrant vagrant 167970 Oct 8 08:14 01-BasicPythonSyntax.html\n-rw-r--r-- 1 vagrant vagrant 37640 Oct 7 10:58 01-BasicPythonSyntax.ipynb\ndrwxr-xr-x 1 vagrant vagrant 136 Oct 8 13:17 02-Builtins\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:15 02-Builtins_files\n-rw-r--r-- 1 vagrant vagrant 73444 Oct 8 08:15 02-Builtins.html\n-rw-r--r-- 1 vagrant vagrant 16244 Oct 7 10:58 02-Builtins.ipynb\ndrwxr-xr-x 1 vagrant vagrant 102 Oct 8 13:41 03-FileIO\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:15 03-FileIO_files\n-rw-r--r-- 1 vagrant vagrant 41620 Oct 8 08:15 03-FileIO.html\n-rw-r--r-- 1 vagrant vagrant 9576 Oct 7 10:58 03-FileIO.ipynb\ndrwxr-xr-x 1 vagrant vagrant 374 Oct 9 06:52 04-UsingModules\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:15 04-UsingModules_files\n-rw-r--r-- 1 vagrant vagrant 137356 Oct 8 08:15 04-UsingModules.html\n-rw-r--r-- 1 vagrant vagrant 45766 Oct 7 10:59 04-UsingModules.ipynb\ndrwxr-xr-x 1 vagrant vagrant 170 Oct 8 15:59 05-Strings\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:15 05-Strings_files\n-rw-r--r-- 1 vagrant vagrant 79928 Oct 8 08:15 05-Strings.html\n-rw-r--r-- 1 vagrant vagrant 17750 Oct 7 10:59 05-Strings.ipynb\ndrwxr-xr-x 1 vagrant vagrant 238 Oct 8 18:02 06a-Packages\ndrwxr-xr-x 1 vagrant vagrant 102 Oct 8 16:26 06-Regex\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:15 06-Regex_files\n-rw-r--r-- 1 vagrant vagrant 64794 Oct 8 08:15 06-Regex.html\n-rw-r--r-- 1 vagrant vagrant 12896 Oct 7 10:59 06-Regex.ipynb\ndrwxr-xr-x 1 vagrant vagrant 102 Oct 9 10:12 07-Functions\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:16 07-Functions_files\n-rw-r--r-- 1 vagrant vagrant 45536 Oct 8 08:16 07-Functions.html\n-rw-r--r-- 1 vagrant vagrant 8062 Oct 9 08:01 07-Functions.ipynb\ndrwxr-xr-x 1 vagrant vagrant 136 Oct 9 10:59 08-AdvancedFunctions\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:16 08-AdvancedFunctions_files\n-rw-r--r-- 1 vagrant vagrant 34295 Oct 8 08:16 08-AdvancedFunctions.html\n-rw-r--r-- 1 vagrant vagrant 5848 Oct 7 17:05 08-AdvancedFunctions.ipynb\ndrwxr-xr-x 1 vagrant vagrant 170 Oct 7 16:25 09-Logging\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:16 09-Logging_files\n-rw-r--r-- 1 vagrant vagrant 47018 Oct 8 08:16 09-Logging.html\n-rw-r--r-- 1 vagrant vagrant 10741 Oct 7 16:48 09-Logging.ipynb\ndrwxr-xr-x 1 vagrant vagrant 102 Oct 9 19:35 10-OOP1\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:16 10-OOP1_files\n-rw-r--r-- 1 vagrant vagrant 35789 Oct 8 08:16 10-OOP1.html\n-rw-r--r-- 1 vagrant vagrant 6375 Oct 7 17:05 10-OOP1.ipynb\ndrwxr-xr-x 1 vagrant vagrant 136 Oct 9 14:19 11-OOP2\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:17 11-OOP2_files\n-rw-r--r-- 1 vagrant vagrant 72396 Oct 8 08:17 11-OOP2.html\n-rw-r--r-- 1 vagrant vagrant 14740 Oct 7 17:50 11-OOP2.ipynb\ndrwxr-xr-x 1 vagrant vagrant 170 Oct 9 15:13 12-Decorators\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:17 12-Decorators_files\n-rw-r--r-- 1 vagrant vagrant 64594 Oct 8 08:17 12-Decorators.html\n-rw-r--r-- 1 vagrant vagrant 12311 Oct 7 18:36 12-Decorators.ipynb\ndrwxr-xr-x 1 vagrant vagrant 102 Oct 9 16:17 13-Generators\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:17 13-GeneratorsAndIterators_files\n-rw-r--r-- 1 vagrant vagrant 71092 Oct 8 08:17 13-GeneratorsAndIterators.html\n-rw-r--r-- 1 vagrant vagrant 12557 Oct 7 19:06 13-GeneratorsAndIterators.ipynb\ndrwxr-xr-x 1 vagrant vagrant 204 Oct 9 17:36 14-ContextManagers\ndrwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:18 14-ContextManagers_files\n-rw-r--r-- 1 vagrant vagrant 47276 Oct 8 08:18 14-ContextManagers.html\n-rw-r--r-- 1 vagrant vagrant 9241 Oct 7 19:42 14-ContextManagers.ipynb\ndrwxr-xr-x 1 vagrant vagrant 544 Oct 8 07:42 15-Threading\ndrwxr-xr-x 1 vagrant vagrant 272 Oct 8 07:46 16-Multiprocessing\ndrwxr-xr-x 1 vagrant vagrant 136 Oct 9 19:30 17-Subprocess\n-rw-r--r-- 1 vagrant vagrant 19419 Oct 9 20:09 17-Subprocess.ipynb\ndrwxr-xr-x 1 vagrant vagrant 204 Oct 9 18:54 18-Virtualenv\ndrwxr-xr-x 1 vagrant vagrant 850 Oct 9 20:42 19-Testing\n-rw-r--r-- 1 vagrant vagrant 25677 Oct 9 20:45 20-MoreModules.ipynb\n-rw-r--r-- 1 vagrant vagrant 1211 Oct 8 08:32 fabfile.py\n-rw-r--r-- 1 vagrant vagrant 1823 Oct 8 08:33 fabfile.pyc\n-rw-r--r-- 1 vagrant vagrant 1548914 Oct 8 08:20 FastTrackToPython.pdf\ndrwxr-xr-x 1 vagrant vagrant 442 Oct 9 19:44 .git\n-rw-r--r-- 1 vagrant vagrant 1358 Oct 9 20:46 index.md\n-rw-r--r-- 1 vagrant vagrant 61 Oct 3 03:19 .vagrant\n-rw-r--r-- 1 vagrant vagrant 4008 Oct 3 03:20 Vagrantfile\n'</pre></div></div></div></div><div tabindex="2" class="cell text_cell border-box-sizing"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 3px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h2>Popen</h2>
<p>The above methods are just wrappers around the <code>Popen</code> constructor:</p></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [11]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>help(subprocess.Popen.__init__)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">help</span><span class="cm-null">(</span><span class="cm-variable">subprocess.Popen.__init__</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>Help on method __init__ in module subprocess:
__init__(self, args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0) unbound subprocess.Popen method
Create new Popen instance.
</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [12]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 47px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>sp = subprocess.Popen('ls', stdout=subprocess.PIPE)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">sp</span><span class="cm-null"> = </span><span class="cm-variable">subprocess.Popen</span><span class="cm-null">(</span><span class="cm-string">'ls'</span><span class="cm-null">, </span><span class="cm-variable">stdout</span><span class="cm-null">=</span><span class="cm-variable">subprocess.PIPE</span><span class="cm-null">)</span></pre><pre><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-variable">sp.stdout</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre><open file '<fdopen>', mode 'rb' at 0x185e930>
</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [13]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>print sp.stdout.read(20)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-variable">sp.stdout.read</span><span class="cm-null">(</span><span class="cm-number">20</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>01-BasicPythonSyntax
</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [14]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>sp.wait()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">sp.wait</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[14]:</div><div class="box_flex1 output_subarea output_text"><pre>0</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [15]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>sp = subprocess.Popen('vi')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">sp</span><span class="cm-null"> = </span><span class="cm-variable">subprocess.Popen</span><span class="cm-null">(</span><span class="cm-string">'vi'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: none;" class="output vbox"></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [16]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>sp.poll()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">sp.poll</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: none;" class="output vbox"></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [17]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>sp.terminate()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">sp.terminate</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: none;" class="output vbox"></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [18]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>sp.wait()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">sp.wait</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[18]:</div><div class="box_flex1 output_subarea output_text"><pre>-15</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [19]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 82px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span> stdout=subprocess.PIPE)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">sp</span><span class="cm-null"> = </span><span class="cm-variable">subprocess.Popen</span><span class="cm-null">(</span></pre><pre><span class="cm-null"> </span><span class="cm-string">'ls'</span><span class="cm-null">,</span></pre><pre><span class="cm-null"> </span><span class="cm-variable">stdout</span><span class="cm-null">=</span><span class="cm-variable">subprocess.PIPE</span><span class="cm-null">)</span></pre><pre><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-variable">sp.communicate</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>('01-BasicPythonSyntax\n01-BasicPythonSyntax_files\n01-BasicPythonSyntax.html\n01-BasicPythonSyntax.ipynb\n02-Builtins\n02-Builtins_files\n02-Builtins.html\n02-Builtins.ipynb\n03-FileIO\n03-FileIO_files\n03-FileIO.html\n03-FileIO.ipynb\n04-UsingModules\n04-UsingModules_files\n04-UsingModules.html\n04-UsingModules.ipynb\n05-Strings\n05-Strings_files\n05-Strings.html\n05-Strings.ipynb\n06a-Packages\n06-Regex\n06-Regex_files\n06-Regex.html\n06-Regex.ipynb\n07-Functions\n07-Functions_files\n07-Functions.html\n07-Functions.ipynb\n08-AdvancedFunctions\n08-AdvancedFunctions_files\n08-AdvancedFunctions.html\n08-AdvancedFunctions.ipynb\n09-Logging\n09-Logging_files\n09-Logging.html\n09-Logging.ipynb\n10-OOP1\n10-OOP1_files\n10-OOP1.html\n10-OOP1.ipynb\n11-OOP2\n11-OOP2_files\n11-OOP2.html\n11-OOP2.ipynb\n12-Decorators\n12-Decorators_files\n12-Decorators.html\n12-Decorators.ipynb\n13-Generators\n13-GeneratorsAndIterators_files\n13-GeneratorsAndIterators.html\n13-GeneratorsAndIterators.ipynb\n14-ContextManagers\n14-ContextManagers_files\n14-ContextManagers.html\n14-ContextManagers.ipynb\n15-Threading\n16-Multiprocessing\n17-Subprocess\n17-Subprocess.ipynb\n18-Virtualenv\n19-Testing\n20-MoreModules.ipynb\nfabfile.py\nfabfile.pyc\nFastTrackToPython.pdf\nindex.md\nVagrantfile\n', None)
</pre></div></div></div></div><div tabindex="2" class="cell text_cell border-box-sizing"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 1px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h2>Pipelines</h2></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [20]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 188px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>print sp2.communicate('FileIO\nSomethingElse')[0]</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">sp1</span><span class="cm-null"> = </span><span class="cm-variable">subprocess.Popen</span><span class="cm-null">(</span></pre><pre><span class="cm-null"> [ </span><span class="cm-string">'ls'</span><span class="cm-null">, </span><span class="cm-string">'-l'</span><span class="cm-null"> ],</span></pre><pre><span class="cm-null"> </span><span class="cm-variable">stdin</span><span class="cm-null">=</span><span class="cm-variable">subprocess.PIPE</span><span class="cm-null">,</span></pre><pre><span class="cm-null"> </span><span class="cm-variable">stdout</span><span class="cm-null">=</span><span class="cm-variable">subprocess.PIPE</span><span class="cm-null">)</span></pre><pre><span class="cm-variable">sp2</span><span class="cm-null"> = </span><span class="cm-variable">subprocess.Popen</span><span class="cm-null">(</span></pre><pre><span class="cm-null"> [</span><span class="cm-string">'grep'</span><span class="cm-null">, </span><span class="cm-string">'FileIO'</span><span class="cm-null">],</span></pre><pre><span class="cm-null"> </span><span class="cm-variable">stdin</span><span class="cm-null">=</span><span class="cm-variable">sp1.stdout</span><span class="cm-null">,</span></pre><pre><span class="cm-null"> </span><span class="cm-variable">stdout</span><span class="cm-null">=</span><span class="cm-variable">subprocess.PIPE</span><span class="cm-null">)</span></pre><pre><span class="cm-variable">sp1.stdin.close</span><span class="cm-null">() </span></pre><pre><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-variable">sp2.communicate</span><span class="cm-null">(</span><span class="cm-string">'FileIO\nSomethingElse'</span><span class="cm-null">)[</span><span class="cm-number">0</span><span class="cm-null">]</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>drwxr-xr-x 1 vagrant vagrant 102 Oct 8 13:41 03-FileIO
drwxr-xr-x 1 vagrant vagrant 510 Oct 8 08:15 03-FileIO_files
-rw-r--r-- 1 vagrant vagrant 41620 Oct 8 08:15 03-FileIO.html
-rw-r--r-- 1 vagrant vagrant 9576 Oct 7 10:58 03-FileIO.ipynb
</pre></div></div></div></div><div tabindex="2" class="cell text_cell border-box-sizing"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 5px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h3>Exercises</h3>
<ul>
<li>Write a script that uses <code>os.listdir()</code> and <code>subprocess.check_output()</code> to run
a command on every file in a directory (for instance, the <code>stat</code> command)</li>
<li>Write a script that creates a pipeline containing two or more commands</li>
</ul></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox ui-widget-content ui-corner-all"><div class="input hbox"><div class="prompt input_prompt">In [20]:</div><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span></span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre> </pre></div></div></div></div></div></div></div></div></div><div style="display: none;" class="output vbox"></div></div><div style="height: 30%;" class="end_space"></div></body></html>