Update version according to OSCI-883
[packages/precise/mcollective.git] / doc / MCollective / Shell.html
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head>
6         <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
8         <title>Class: MCollective::Shell</title>
9
10         <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
11
12         <script src="../js/jquery.js" type="text/javascript"
13                 charset="utf-8"></script>
14         <script src="../js/thickbox-compressed.js" type="text/javascript"
15                 charset="utf-8"></script>
16         <script src="../js/quicksearch.js" type="text/javascript"
17                 charset="utf-8"></script>
18         <script src="../js/darkfish.js" type="text/javascript"
19                 charset="utf-8"></script>
20
21 </head>
22 <body class="class">
23
24         <div id="metadata">
25                 <div id="file-metadata">
26                         <div id="file-list-section" class="section">
27                                 <h3 class="section-header">In Files</h3>
28                                 <div class="section-body">
29                                         <ul>
30                                         
31                                                 <li><a href="../lib/mcollective/shell_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
32                                                         class="thickbox" title="lib/mcollective/shell.rb">lib/mcollective/shell.rb</a></li>
33                                         
34                                         </ul>
35                                 </div>
36                         </div>
37
38                         
39                 </div>
40
41                 <div id="class-metadata">
42
43                         <!-- Parent Class -->
44                         
45                         <div id="parent-class-section" class="section">
46                                 <h3 class="section-header">Parent</h3>
47                                 
48                                 <p class="link"><a href="../Object.html">Object</a></p>
49                                 
50                         </div>
51                         
52
53                         <!-- Namespace Contents -->
54                         
55
56                         <!-- Method Quickref -->
57                         
58                         <div id="method-list-section" class="section">
59                                 <h3 class="section-header">Methods</h3>
60                                 <ul class="link-list">
61                                         
62                                         <li><a href="#M000358">::new</a></li>
63                                         
64                                         <li><a href="#M000365">#runcommand</a></li>
65                                         
66                                 </ul>
67                         </div>
68                         
69
70                         <!-- Included Modules -->
71                         
72                 </div>
73
74                 <div id="project-metadata">
75                         
76                         
77                         <div id="fileindex-section" class="section project-section">
78                                 <h3 class="section-header">Files</h3>
79                                 <ul>
80                                 
81                                         <li class="file"><a href="../COPYING.html">COPYING</a></li>
82                                 
83                                         <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
84                                 
85                                         <li class="file"><a href="../README.html">README</a></li>
86                                 
87                                         <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
88                                 
89                                         <li class="file"><a href="../etc/client_cfg_dist.html">client.cfg.dist</a></li>
90                                 
91                                         <li class="file"><a href="../etc/data-help_erb.html">data-help.erb</a></li>
92                                 
93                                         <li class="file"><a href="../etc/discovery-help_erb.html">discovery-help.erb</a></li>
94                                 
95                                         <li class="file"><a href="../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
96                                 
97                                         <li class="file"><a href="../etc/metadata-help_erb.html">metadata-help.erb</a></li>
98                                 
99                                         <li class="file"><a href="../etc/msg-help_erb.html">msg-help.erb</a></li>
100                                 
101                                         <li class="file"><a href="../etc/rpc-help_erb.html">rpc-help.erb</a></li>
102                                 
103                                         <li class="file"><a href="../etc/server_cfg_dist.html">server.cfg.dist</a></li>
104                                 
105                                         <li class="file"><a href="../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
106                                 
107                                         <li class="file"><a href="../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
108                                 
109                                         <li class="file"><a href="../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
110                                 
111                                         <li class="file"><a href="../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
112                                 
113                                         <li class="file"><a href="../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
114                                 
115                                         <li class="file"><a href="../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
116                                 
117                                         <li class="file"><a href="../lib/mcollective/locales/en_yml.html">en.yml</a></li>
118                                 
119                                         <li class="file"><a href="../mcollective_init.html">mcollective.init</a></li>
120                                 
121                                 </ul>
122                         </div>
123                         
124
125                         <div id="classindex-section" class="section project-section">
126                                 <h3 class="section-header">Class Index
127                                         <span class="search-toggle"><img src="../images/find.png"
128                                                 height="16" width="16" alt="[+]"
129                                                 title="show/hide quicksearch" /></span></h3>
130                                 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
131                                 <fieldset>
132                                         <legend>Quicksearch</legend>
133                                         <input type="text" name="quicksearch" value=""
134                                                 class="quicksearch-field" />
135                                 </fieldset>
136                                 </form>
137
138                                 <ul class="link-list">
139                                 
140                                         <li><a href="../MCollective.html">MCollective</a></li>
141                                 
142                                         <li><a href="../MCollective/Agent.html">MCollective::Agent</a></li>
143                                 
144                                         <li><a href="../MCollective/Agents.html">MCollective::Agents</a></li>
145                                 
146                                         <li><a href="../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
147                                 
148                                         <li><a href="../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
149                                 
150                                         <li><a href="../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
151                                 
152                                         <li><a href="../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
153                                 
154                                         <li><a href="../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
155                                 
156                                         <li><a href="../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
157                                 
158                                         <li><a href="../MCollective/Application.html">MCollective::Application</a></li>
159                                 
160                                         <li><a href="../MCollective/Applications.html">MCollective::Applications</a></li>
161                                 
162                                         <li><a href="../MCollective/Cache.html">MCollective::Cache</a></li>
163                                 
164                                         <li><a href="../MCollective/Client.html">MCollective::Client</a></li>
165                                 
166                                         <li><a href="../MCollective/CodedError.html">MCollective::CodedError</a></li>
167                                 
168                                         <li><a href="../MCollective/Config.html">MCollective::Config</a></li>
169                                 
170                                         <li><a href="../MCollective/Connector.html">MCollective::Connector</a></li>
171                                 
172                                         <li><a href="../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
173                                 
174                                         <li><a href="../MCollective/DDL.html">MCollective::DDL</a></li>
175                                 
176                                         <li><a href="../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
177                                 
178                                         <li><a href="../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
179                                 
180                                         <li><a href="../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
181                                 
182                                         <li><a href="../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
183                                 
184                                         <li><a href="../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
185                                 
186                                         <li><a href="../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
187                                 
188                                         <li><a href="../MCollective/Data.html">MCollective::Data</a></li>
189                                 
190                                         <li><a href="../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
191                                 
192                                         <li><a href="../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
193                                 
194                                         <li><a href="../MCollective/Discovery.html">MCollective::Discovery</a></li>
195                                 
196                                         <li><a href="../MCollective/Facts.html">MCollective::Facts</a></li>
197                                 
198                                         <li><a href="../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
199                                 
200                                         <li><a href="../MCollective/Generators.html">MCollective::Generators</a></li>
201                                 
202                                         <li><a href="../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
203                                 
204                                         <li><a href="../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
205                                 
206                                         <li><a href="../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
207                                 
208                                         <li><a href="../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
209                                 
210                                         <li><a href="../MCollective/Log.html">MCollective::Log</a></li>
211                                 
212                                         <li><a href="../MCollective/Logger.html">MCollective::Logger</a></li>
213                                 
214                                         <li><a href="../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
215                                 
216                                         <li><a href="../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
217                                 
218                                         <li><a href="../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
219                                 
220                                         <li><a href="../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
221                                 
222                                         <li><a href="../MCollective/Matcher.html">MCollective::Matcher</a></li>
223                                 
224                                         <li><a href="../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
225                                 
226                                         <li><a href="../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
227                                 
228                                         <li><a href="../MCollective/Message.html">MCollective::Message</a></li>
229                                 
230                                         <li><a href="../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
231                                 
232                                         <li><a href="../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
233                                 
234                                         <li><a href="../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
235                                 
236                                         <li><a href="../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
237                                 
238                                         <li><a href="../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
239                                 
240                                         <li><a href="../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
241                                 
242                                         <li><a href="../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
243                                 
244                                         <li><a href="../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
245                                 
246                                         <li><a href="../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
247                                 
248                                         <li><a href="../MCollective/RPC.html">MCollective::RPC</a></li>
249                                 
250                                         <li><a href="../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
251                                 
252                                         <li><a href="../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
253                                 
254                                         <li><a href="../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
255                                 
256                                         <li><a href="../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
257                                 
258                                         <li><a href="../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
259                                 
260                                         <li><a href="../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
261                                 
262                                         <li><a href="../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
263                                 
264                                         <li><a href="../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
265                                 
266                                         <li><a href="../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
267                                 
268                                         <li><a href="../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
269                                 
270                                         <li><a href="../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
271                                 
272                                         <li><a href="../MCollective/RPCError.html">MCollective::RPCError</a></li>
273                                 
274                                         <li><a href="../MCollective/Registration.html">MCollective::Registration</a></li>
275                                 
276                                         <li><a href="../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
277                                 
278                                         <li><a href="../MCollective/Runner.html">MCollective::Runner</a></li>
279                                 
280                                         <li><a href="../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
281                                 
282                                         <li><a href="../MCollective/SSL.html">MCollective::SSL</a></li>
283                                 
284                                         <li><a href="../MCollective/Security.html">MCollective::Security</a></li>
285                                 
286                                         <li><a href="../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
287                                 
288                                         <li><a href="../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
289                                 
290                                         <li><a href="../MCollective/Shell.html">MCollective::Shell</a></li>
291                                 
292                                         <li><a href="../MCollective/Translatable.html">MCollective::Translatable</a></li>
293                                 
294                                         <li><a href="../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
295                                 
296                                         <li><a href="../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
297                                 
298                                         <li><a href="../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
299                                 
300                                         <li><a href="../MCollective/Util.html">MCollective::Util</a></li>
301                                 
302                                         <li><a href="../MCollective/Validator.html">MCollective::Validator</a></li>
303                                 
304                                         <li><a href="../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
305                                 
306                                         <li><a href="../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
307                                 
308                                         <li><a href="../Array.html">Array</a></li>
309                                 
310                                         <li><a href="../Dir.html">Dir</a></li>
311                                 
312                                         <li><a href="../Object.html">Object</a></li>
313                                 
314                                         <li><a href="../String.html">String</a></li>
315                                 
316                                         <li><a href="../Symbol.html">Symbol</a></li>
317                                 
318                                 </ul>
319                                 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
320                         </div>
321
322                         
323                 </div>
324         </div>
325
326         <div id="documentation">
327                 <h1 class="class">MCollective::Shell</h1>
328
329                 <div id="description">
330                         <p>
331 Wrapper around systemu that handles executing of system commands in a way
332 that makes stdout, stderr and status available. Supports timeouts and sets
333 a default sane environment.
334 </p>
335 <pre>
336   s = Shell.new(&quot;date&quot;, opts)
337   s.runcommand
338   puts s.stdout
339   puts s.stderr
340   puts s.status.exitstatus
341 </pre>
342 <p>
343 Options hash can have:
344 </p>
345 <pre>
346   cwd         - the working directory the command will be run from
347   stdin       - a string that will be sent to stdin of the program
348   stdout      - a variable that will receive stdout, must support &lt;&lt;
349   stderr      - a variable that will receive stdin, must support &lt;&lt;
350   environment - the shell environment, defaults to include LC_ALL=C
351                 set to nil to clear the environment even of LC_ALL
352   timeout     - a timeout in seconds after which the subprocess is killed,
353                 the special value :on_thread_exit kills the subprocess
354                 when the invoking thread (typically the agent) has ended
355 </pre>
356
357                 </div>
358
359                 <!-- Constants -->
360                 
361
362                 <!-- Attributes -->
363                 
364                 <div id="attribute-method-details" class="method-section section">
365                         <h3 class="section-header">Attributes</h3>
366
367                         
368                         <div id="environment-attribute-method" class="method-detail">
369                                 <a name="environment"></a>
370                                 
371                                 <div class="method-heading attribute-method-heading">
372                                         <span class="method-name">environment</span><span
373                                                 class="attribute-access-type">[R]</span>
374                                 </div>
375
376                                 <div class="method-description">
377                                 
378                                 <p class="missing-docs">(Not documented)</p>
379                                 
380                                 </div>
381                         </div>
382                         
383                         <div id="command-attribute-method" class="method-detail">
384                                 <a name="command"></a>
385                                 
386                                 <div class="method-heading attribute-method-heading">
387                                         <span class="method-name">command</span><span
388                                                 class="attribute-access-type">[R]</span>
389                                 </div>
390
391                                 <div class="method-description">
392                                 
393                                 <p class="missing-docs">(Not documented)</p>
394                                 
395                                 </div>
396                         </div>
397                         
398                         <div id="status-attribute-method" class="method-detail">
399                                 <a name="status"></a>
400                                 
401                                 <div class="method-heading attribute-method-heading">
402                                         <span class="method-name">status</span><span
403                                                 class="attribute-access-type">[R]</span>
404                                 </div>
405
406                                 <div class="method-description">
407                                 
408                                 <p class="missing-docs">(Not documented)</p>
409                                 
410                                 </div>
411                         </div>
412                         
413                         <div id="stdout-attribute-method" class="method-detail">
414                                 <a name="stdout"></a>
415                                 
416                                 <div class="method-heading attribute-method-heading">
417                                         <span class="method-name">stdout</span><span
418                                                 class="attribute-access-type">[R]</span>
419                                 </div>
420
421                                 <div class="method-description">
422                                 
423                                 <p class="missing-docs">(Not documented)</p>
424                                 
425                                 </div>
426                         </div>
427                         
428                         <div id="stderr-attribute-method" class="method-detail">
429                                 <a name="stderr"></a>
430                                 
431                                 <div class="method-heading attribute-method-heading">
432                                         <span class="method-name">stderr</span><span
433                                                 class="attribute-access-type">[R]</span>
434                                 </div>
435
436                                 <div class="method-description">
437                                 
438                                 <p class="missing-docs">(Not documented)</p>
439                                 
440                                 </div>
441                         </div>
442                         
443                         <div id="stdin-attribute-method" class="method-detail">
444                                 <a name="stdin"></a>
445                                 
446                                 <div class="method-heading attribute-method-heading">
447                                         <span class="method-name">stdin</span><span
448                                                 class="attribute-access-type">[R]</span>
449                                 </div>
450
451                                 <div class="method-description">
452                                 
453                                 <p class="missing-docs">(Not documented)</p>
454                                 
455                                 </div>
456                         </div>
457                         
458                         <div id="cwd-attribute-method" class="method-detail">
459                                 <a name="cwd"></a>
460                                 
461                                 <div class="method-heading attribute-method-heading">
462                                         <span class="method-name">cwd</span><span
463                                                 class="attribute-access-type">[R]</span>
464                                 </div>
465
466                                 <div class="method-description">
467                                 
468                                 <p class="missing-docs">(Not documented)</p>
469                                 
470                                 </div>
471                         </div>
472                         
473                         <div id="timeout-attribute-method" class="method-detail">
474                                 <a name="timeout"></a>
475                                 
476                                 <div class="method-heading attribute-method-heading">
477                                         <span class="method-name">timeout</span><span
478                                                 class="attribute-access-type">[R]</span>
479                                 </div>
480
481                                 <div class="method-description">
482                                 
483                                 <p class="missing-docs">(Not documented)</p>
484                                 
485                                 </div>
486                         </div>
487                         
488                 </div>
489                 
490
491                 <!-- Methods -->
492                 
493                 <div id="public-class-method-details" class="method-section section">
494                         <h3 class="section-header">Public Class Methods</h3>
495
496                 
497                         <div id="new-method" class="method-detail ">
498                                 <a name="M000358"></a>
499
500                                 <div class="method-heading">
501                                 
502                                         <span class="method-name">new</span><span
503                                                 class="method-args">(command, options={})</span>
504                                         <span class="method-click-advice">click to toggle source</span>
505                                 
506                                 </div>
507
508                                 <div class="method-description">
509                                         
510                                         <p class="missing-docs">(Not documented)</p>
511                                         
512
513                                         
514                                         <div class="method-source-code"
515                                                 id="new-source">
516 <pre>
517     <span class="ruby-comment cmt"># File lib/mcollective/shell.rb, line 27</span>
518 27:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">command</span>, <span class="ruby-identifier">options</span>={})
519 28:       <span class="ruby-ivar">@environment</span> = {<span class="ruby-value str">&quot;LC_ALL&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;C&quot;</span>}
520 29:       <span class="ruby-ivar">@command</span> = <span class="ruby-identifier">command</span>
521 30:       <span class="ruby-ivar">@status</span> = <span class="ruby-keyword kw">nil</span>
522 31:       <span class="ruby-ivar">@stdout</span> = <span class="ruby-value str">&quot;&quot;</span>
523 32:       <span class="ruby-ivar">@stderr</span> = <span class="ruby-value str">&quot;&quot;</span>
524 33:       <span class="ruby-ivar">@stdin</span> = <span class="ruby-keyword kw">nil</span>
525 34:       <span class="ruby-ivar">@cwd</span> = <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">tmpdir</span>
526 35:       <span class="ruby-ivar">@timeout</span> = <span class="ruby-keyword kw">nil</span>
527 36: 
528 37:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opt</span>, <span class="ruby-identifier">val</span><span class="ruby-operator">|</span>
529 38:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">to_s</span>
530 39:           <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;stdout&quot;</span>
531 40:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;stdout should support &lt;&lt;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">&quot;&lt;&lt;&quot;</span>)
532 41:             <span class="ruby-ivar">@stdout</span> = <span class="ruby-identifier">val</span>
533 42: 
534 43:           <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;stderr&quot;</span>
535 44:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;stderr should support &lt;&lt;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">&quot;&lt;&lt;&quot;</span>)
536 45:             <span class="ruby-ivar">@stderr</span> = <span class="ruby-identifier">val</span>
537 46: 
538 47:           <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;stdin&quot;</span>
539 48:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;stdin should be a String&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
540 49:             <span class="ruby-ivar">@stdin</span> = <span class="ruby-identifier">val</span>
541 50: 
542 51:           <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;cwd&quot;</span>
543 52:             <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Directory #{val} does not exist&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">val</span>)
544 53:             <span class="ruby-ivar">@cwd</span> = <span class="ruby-identifier">val</span>
545 54: 
546 55:           <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;environment&quot;</span>
547 56:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">nil?</span>
548 57:               <span class="ruby-ivar">@environment</span> = {}
549 58:             <span class="ruby-keyword kw">else</span>
550 59:               <span class="ruby-ivar">@environment</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">val</span>.<span class="ruby-identifier">dup</span>)
551 60:             <span class="ruby-keyword kw">end</span>
552 61:           <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;timeout&quot;</span>
553 62:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;timeout should be a positive integer or the symbol :on_thread_exit symbol&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">:on_thread_exit</span>) <span class="ruby-operator">||</span> ( <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">val</span><span class="ruby-operator">&gt;</span><span class="ruby-value">0</span> )
554 63:             <span class="ruby-ivar">@timeout</span> = <span class="ruby-identifier">val</span>
555 64:         <span class="ruby-keyword kw">end</span>
556 65:       <span class="ruby-keyword kw">end</span>
557 66:     <span class="ruby-keyword kw">end</span></pre>
558                                         </div>
559                                         
560                                 </div>
561
562                                 
563                         </div>
564
565                 
566                 </div>
567         
568                 <div id="public-instance-method-details" class="method-section section">
569                         <h3 class="section-header">Public Instance Methods</h3>
570
571                 
572                         <div id="runcommand-method" class="method-detail ">
573                                 <a name="M000365"></a>
574
575                                 <div class="method-heading">
576                                 
577                                         <span class="method-name">runcommand</span><span
578                                                 class="method-args">()</span>
579                                         <span class="method-click-advice">click to toggle source</span>
580                                 
581                                 </div>
582
583                                 <div class="method-description">
584                                         
585                                         <p>
586 Actually does the systemu call passing in the correct environment, stdout
587 and stderr
588 </p>
589                                         
590
591                                         
592                                         <div class="method-source-code"
593                                                 id="runcommand-source">
594 <pre>
595      <span class="ruby-comment cmt"># File lib/mcollective/shell.rb, line 69</span>
596  69:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">runcommand</span>
597  70:       <span class="ruby-identifier">opts</span> = {<span class="ruby-value str">&quot;env&quot;</span>    =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@environment</span>,
598  71:               <span class="ruby-value str">&quot;stdout&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@stdout</span>,
599  72:               <span class="ruby-value str">&quot;stderr&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@stderr</span>,
600  73:               <span class="ruby-value str">&quot;cwd&quot;</span>    =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@cwd</span>}
601  74: 
602  75:       <span class="ruby-identifier">opts</span>[<span class="ruby-value str">&quot;stdin&quot;</span>] = <span class="ruby-ivar">@stdin</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@stdin</span>
603  76: 
604  77: 
605  78:       <span class="ruby-identifier">thread</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>
606  79:       <span class="ruby-comment cmt"># Start a double fork and exec with systemu which implies a guard thread.</span>
607  80:       <span class="ruby-comment cmt"># If a valid timeout is configured the guard thread will terminate the</span>
608  81:       <span class="ruby-comment cmt"># executing process and reap the pid.</span>
609  82:       <span class="ruby-comment cmt"># If no timeout is specified the process will run to completion with the</span>
610  83:       <span class="ruby-comment cmt"># guard thread reaping the pid on completion.</span>
611  84:       <span class="ruby-ivar">@status</span> = <span class="ruby-identifier">systemu</span>(<span class="ruby-ivar">@command</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cid</span><span class="ruby-operator">|</span>
612  85:         <span class="ruby-keyword kw">begin</span>
613  86:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">timeout</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Fixnum</span>)
614  87:             <span class="ruby-comment cmt"># wait for the specified timeout</span>
615  88:             <span class="ruby-identifier">sleep</span> <span class="ruby-identifier">timeout</span>
616  89:           <span class="ruby-keyword kw">else</span>
617  90:             <span class="ruby-comment cmt"># sleep while the agent thread is still alive</span>
618  91:             <span class="ruby-keyword kw">while</span>(<span class="ruby-identifier">thread</span>.<span class="ruby-identifier">alive?</span>)
619  92:               <span class="ruby-identifier">sleep</span> <span class="ruby-value">0</span><span class="ruby-value">.1</span>
620  93:             <span class="ruby-keyword kw">end</span>
621  94:           <span class="ruby-keyword kw">end</span>
622  95: 
623  96:           <span class="ruby-comment cmt"># if the process is still running</span>
624  97:           <span class="ruby-keyword kw">if</span> (<span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">cid</span>))
625  98:             <span class="ruby-comment cmt"># and a timeout was specified</span>
626  99:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">timeout</span>
627 100:               <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">windows?</span>
628 101:                 <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value str">'KILL'</span>, <span class="ruby-identifier">cid</span>)
629 102:               <span class="ruby-keyword kw">else</span>
630 103:                 <span class="ruby-comment cmt"># Kill the process</span>
631 104:                 <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value str">'TERM'</span>, <span class="ruby-identifier">cid</span>)
632 105:                 <span class="ruby-identifier">sleep</span> <span class="ruby-value">2</span>
633 106:                 <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value str">'KILL'</span>, <span class="ruby-identifier">cid</span>) <span class="ruby-keyword kw">if</span> (<span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">cid</span>))
634 107:               <span class="ruby-keyword kw">end</span>
635 108:             <span class="ruby-keyword kw">end</span>
636 109:             <span class="ruby-comment cmt"># only wait if the parent thread is dead</span>
637 110:             <span class="ruby-constant">Process</span>.<span class="ruby-identifier">waitpid</span>(<span class="ruby-identifier">cid</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">thread</span>.<span class="ruby-identifier">alive?</span>
638 111:           <span class="ruby-keyword kw">end</span>
639 112:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">SystemExit</span>
640 113:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span>
641 114:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECHILD</span>
642 115:           <span class="ruby-constant">Log</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-node">&quot;Could not reap process '#{cid}'.&quot;</span>)
643 116:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
644 117:           <span class="ruby-constant">Log</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Unexpected exception received while waiting for child process: #{e.class}: #{e}&quot;</span>)
645 118:         <span class="ruby-keyword kw">end</span>
646 119:       <span class="ruby-keyword kw">end</span>
647 120:       <span class="ruby-ivar">@status</span>.<span class="ruby-identifier">thread</span>.<span class="ruby-identifier">kill</span>
648 121:       <span class="ruby-ivar">@status</span>
649 122:     <span class="ruby-keyword kw">end</span></pre>
650                                         </div>
651                                         
652                                 </div>
653
654                                 
655                         </div>
656
657                 
658                 </div>
659         
660
661         </div>
662
663
664         <div id="rdoc-debugging-section-dump" class="debugging-section">
665         
666                 <p>Disabled; run with --debug to generate this.</p>
667         
668         </div>
669
670         <div id="validator-badges">
671                 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
672                 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
673                         Rdoc Generator</a> 1.1.6</small>.</p>
674         </div>
675
676 </body>
677 </html>
678