Module: Deployman::Component::Output

Defined in:
lib/deployman/component/output.rb

Class Method Summary collapse

Class Method Details

.get_outputObject

get both outputs from tempfiles will destroy tempfiles after read



26
27
28
29
30
31
32
# File 'lib/deployman/component/output.rb', line 26

def self.get_output
	# restore original output (will write all outputs to tempfiles)
	$stdout.reopen @@stdout
	$stderr.reopen @@stderr
	# return tempfile content
	{'stdout' => @@stdout_temp.read, 'stderr' => @@stderr_temp.read}
end

.get_stderrObject

get stderr from tempfile will destroy tempfile after read



47
48
49
50
51
52
# File 'lib/deployman/component/output.rb', line 47

def self.get_stderr
	# restore original output (will write all outputs to tempfiles)
	$stderr.reopen @@stderr
	# return tempfile content
	@@stderr_temp.read
end

.get_stdoutObject

get stdout from tempfile will destroy tempfile after read



37
38
39
40
41
42
# File 'lib/deployman/component/output.rb', line 37

def self.get_stdout
	# restore original output (will write all outputs to tempfiles)
	$stdout.reopen @@stdout
	# return tempfile content
	@@stdout_temp.read
end

.redirect_outputObject

redirect outputs into tempfiles



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/deployman/component/output.rb', line 7

def self.redirect_output

	# backup original outputs
	@@stdout = $stdout.dup
	@@stderr = $stderr.dup

	# open tempfiles
	# will create temp files in /tmp/
	@@stdout_temp = Tempfile.open 'stdout-redirect'
	@@stderr_temp = Tempfile.open 'stderr-redirect'

	# redirect outputs to tempfiles
	$stdout.reopen @@stdout_temp.path, 'a'
	$stderr.reopen @@stderr_temp.path, 'a'
end