SlideShare uma empresa Scribd logo
1 de 23
Piloting processes through standard I/O in Ruby Jan 25 th  2012 Muriel Salvan Open Source Lead developer and architect X-Aeon Solutions http://x-aeon.com
The needs ,[object Object]
Solutions tested ,[object Object]
Kernel::open
systemu
PTY::spawn
ChildProcess
Open3::popen3
ProcessPilot
Aruba  (used with  Cucumber )
External test program ,[object Object]
This is Line 2, after sleep 1
Enter string 1:  My String 1
String 1 entered: My String 1
This is Line 1 on STDERR, before sleep 1
This is Line 2 on STDERR, after sleep 1
Enter string 2 from STDERR:   My String 2
String 2 entered: My String 2
This is Line 3, before sleep 1
This is Line 4, after sleep 1 Output : Output on STDOUT only Output : Output on STDERR only Output : Output for interactive tests only Input : Input taken from STDIN sleep 1 sleep 1 sleep 1 Input from stdin Input from stdin
IO::popen IO . popen ( 'ruby test.rb' ,  'r+' )   do   | io | io . write ( "My String 1  My String 2  " ) io . close_write puts   "stdout: #{io.read}” end
IO::popen ,[object Object]
stderr  support only for  Ruby > 1.9

Mais conteúdo relacionado

Mais procurados

2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
phanleson
 

Mais procurados (20)

System Hacking Tutorial #3 - Buffer Overflow - Egg Hunting
System Hacking Tutorial #3 - Buffer Overflow - Egg HuntingSystem Hacking Tutorial #3 - Buffer Overflow - Egg Hunting
System Hacking Tutorial #3 - Buffer Overflow - Egg Hunting
 
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
 
Qt Translations
Qt TranslationsQt Translations
Qt Translations
 
Control hijacking
Control hijackingControl hijacking
Control hijacking
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
Regular Expression (RegExp)
Regular Expression (RegExp)Regular Expression (RegExp)
Regular Expression (RegExp)
 
Python Lecture 7
Python Lecture 7Python Lecture 7
Python Lecture 7
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Improving file formats
Improving file formatsImproving file formats
Improving file formats
 
Антон Наумович, Система автоматической крэш-аналитики своими средствами
Антон Наумович, Система автоматической крэш-аналитики своими средствамиАнтон Наумович, Система автоматической крэш-аналитики своими средствами
Антон Наумович, Система автоматической крэш-аналитики своими средствами
 
C++11 talk
C++11 talkC++11 talk
C++11 talk
 
Introduction to Clime
Introduction to ClimeIntroduction to Clime
Introduction to Clime
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__
 

Destaque

Destaque (10)

Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013
 
Ruby and Docker on Rails
Ruby and Docker on RailsRuby and Docker on Rails
Ruby and Docker on Rails
 
DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011
 
Ruby 2.0 at the Ruby drink-up of Sophia, February 2013
Ruby 2.0 at the Ruby drink-up of Sophia, February 2013Ruby 2.0 at the Ruby drink-up of Sophia, February 2013
Ruby 2.0 at the Ruby drink-up of Sophia, February 2013
 
Ruby and Twitter at the Ruby drink-up of Sophia, January 2013
Ruby and Twitter at the Ruby drink-up of Sophia, January 2013Ruby and Twitter at the Ruby drink-up of Sophia, January 2013
Ruby and Twitter at the Ruby drink-up of Sophia, January 2013
 
Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012
 
Quines—Programming your way back to where you were
Quines—Programming your way back to where you wereQuines—Programming your way back to where you were
Quines—Programming your way back to where you were
 
The Dark Side of Programming Languages
The Dark Side of Programming LanguagesThe Dark Side of Programming Languages
The Dark Side of Programming Languages
 
Untitled talk at Riviera.rb
Untitled talk at Riviera.rbUntitled talk at Riviera.rb
Untitled talk at Riviera.rb
 

Semelhante a Piloting processes through std IO at the Ruby Drink-up of Sophia, January 2012

System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
ashukiller7
 
Unix And C
Unix And CUnix And C
Unix And C
Dr.Ravi
 

Semelhante a Piloting processes through std IO at the Ruby Drink-up of Sophia, January 2012 (20)

OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoOSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with Go
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
 
Python in 90 Minutes
Python in 90 MinutesPython in 90 Minutes
Python in 90 Minutes
 
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
 
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers Toolbox
 
Rustでパケットと戯れる
Rustでパケットと戯れるRustでパケットと戯れる
Rustでパケットと戯れる
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
Fuzzing: Finding Your Own Bugs and 0days! 2.0
Fuzzing: Finding Your Own Bugs and 0days! 2.0Fuzzing: Finding Your Own Bugs and 0days! 2.0
Fuzzing: Finding Your Own Bugs and 0days! 2.0
 
6. processes and threads
6. processes and threads6. processes and threads
6. processes and threads
 
Unix And C
Unix And CUnix And C
Unix And C
 
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
 
lec4.docx
lec4.docxlec4.docx
lec4.docx
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
 
pcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFun
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Bioinformatica 27-10-2011-p4-files
Bioinformatica 27-10-2011-p4-filesBioinformatica 27-10-2011-p4-files
Bioinformatica 27-10-2011-p4-files
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Piloting processes through std IO at the Ruby Drink-up of Sophia, January 2012

  • 1. Piloting processes through standard I/O in Ruby Jan 25 th 2012 Muriel Salvan Open Source Lead developer and architect X-Aeon Solutions http://x-aeon.com
  • 2.
  • 3.
  • 10. Aruba (used with Cucumber )
  • 11.
  • 12. This is Line 2, after sleep 1
  • 13. Enter string 1: My String 1
  • 14. String 1 entered: My String 1
  • 15. This is Line 1 on STDERR, before sleep 1
  • 16. This is Line 2 on STDERR, after sleep 1
  • 17. Enter string 2 from STDERR: My String 2
  • 18. String 2 entered: My String 2
  • 19. This is Line 3, before sleep 1
  • 20. This is Line 4, after sleep 1 Output : Output on STDOUT only Output : Output on STDERR only Output : Output for interactive tests only Input : Input taken from STDIN sleep 1 sleep 1 sleep 1 Input from stdin Input from stdin
  • 21. IO::popen IO . popen ( 'ruby test.rb' , 'r+' ) do | io | io . write ( "My String 1 My String 2 " ) io . close_write puts "stdout: #{io.read}” end
  • 22.
  • 23. stderr support only for Ruby > 1.9
  • 24. stderr support does not work on Windows
  • 25. Does not work with Ruby programs that don't explicitly turn off stdout internal cache
  • 26. Kernel::open Kernel :: open ( '|ruby test.rb', 'r+' ) do | io | puts io . gets # stdout Line 1 puts io . gets # stdout Line 2 puts io . read ( 31 ) # stdout Prompt sleep 1 io . write ( "My String 1 " ) puts io . gets # stdout String 1 sleep 1 io . write ( "My String 2 " ) puts io . gets # stdout Line 3 puts io . gets # stdout Line 4 end
  • 27.
  • 28. Does not work with Ruby programs that don't explicitly turn off stdout internal cache
  • 29. systemu require 'systemu' status, stdout, stderr = systemu ( 'ruby test.rb' , 0 => "My String 1 My String 2 " ) puts "stdout: #{stdout}" puts "stderr: #{stderr}"
  • 30.
  • 31. stdin must be given to the process at startup time => No real time
  • 32. stdout/err can only be accessed when process has exited => No real time
  • 33. PTY::spawn require 'pty' PTY ::spawn ( 'ruby test.rb' ) do | stdout, stdin, pid | puts stdout. gets # stdout Line 1 puts stdout. gets # stdout Line 2 puts stdout. read ( 31 ) # stdout Prompt sleep 1 stdin. write ( "My String 1 " ) puts stdout. gets # Extra for input echoed puts stdout. gets # stdout String 1 puts stdout. gets # Should be on stderr puts stdout. gets # Should be on stderr puts stdout. read ( 43 ) # Should be on stderr sleep 1 stdin. write ( "My String 2 " ) puts stdout. gets # Extra for input echoed puts stdout. gets # Should be on stderr puts stdout. gets # stdout Line 3 puts stdout. gets # stdout Line 4 end
  • 34.
  • 35. Mix stdout and stderr in the same IO => No stderr support
  • 36. Echoes all input from stdin to stdout
  • 37. ChildProcess require 'childprocess' require 'tempfile' lProcess = ChildProcess. build ( 'ruby' , 'test.rb' ) lProcess. duplex = true Tempfile . open ( 'stdout' ) do | oStdOUT | lProcess. io . stdout = oStdOUT Tempfile . open ( 'stderr' ) do | oStdERR | lProcess. io . stderr = oStdERR lProcess. start stdout = File . open ( oStdOUT. path , 'r' ) stderr = File . open ( oStdERR. path , 'r' ) stdin = lProcess. io . stdin waitfor ( stdout, 'This is Line 2' ) # Need active wait sleep 1 stdin. write ( "My String 1 " ) waitfor ( stderr, 'This is Line 2' ) # Need active wait sleep 1 stdin. write ( "My String 2 " ) waitfor ( stdout, 'This is Line 4' ) # Need active wait end end
  • 38.
  • 39. Need active blocking read on stdout and stderr to wait for next line
  • 40. Very unstable on native Windows
  • 41. Does not work with Ruby programs that don't explicitly turn off stdout internal cache
  • 42. Open3::popen3 require 'open3' Open3 ::popen3 ( 'ruby test.rb' ) do | stdin, stdout, stderr, wait_thr | puts stdout. gets # stdout Line 1 puts stdout. gets # stdout Line 2 puts stdout. read ( 31 ) # stdout Prompt sleep 1 stdin. write ( "My String 1 " ) puts stdout. gets # stdout String 1 puts stderr. gets # stderr Line 1 puts stderr. gets # stderr Line 2 puts stderr. read ( 43 ) # stderr Prompt sleep 1 stdin. write ( "My String 2 " ) puts stderr. gets # stderr String 2 puts stdout. gets # stdout Line 3 puts stdout. gets # stdout Line 4 end
  • 43.
  • 44. Works on any OS
  • 45.
  • 46. ProcessPilot require 'processpilot/processpilot' ProcessPilot ::pilot ( 'ruby' , 'test.rb' ) do | stdin, stdout, stderr, childproc | puts stdout. gets # stdout Line 1 puts stdout. gets # stdout Line 2 puts stdout. read ( 31 ) # stdout Prompt sleep 1 stdin. write ( "My String 1 " ) puts stdout. gets # stdout String 1 puts stderr. gets # stderr Line 1 puts stderr. gets # stderr Line 2 puts stderr. read ( 43 ) # stderr Prompt sleep 1 stdin. write ( "My String 2 " ) puts stderr. gets # stderr String 2 puts stdout. gets # stdout Line 3 puts stdout. gets # stdout Line 4 end
  • 47.
  • 48. Works on any OS
  • 49. Works with all Ruby programs , even if they don't explicitly turn off stdout internal cache
  • 51.
  • 52. Aruba When I run `ruby test.rb` interactively And I type "My String 1" And I type "My String 2" Then the stdout should contain : """ This is Line 1, before sleep 1 This is Line 2, after sleep 1 Enter string 1: String 1 entered: My String 1 This is Line 3, before sleep 1 This is Line 4, after sleep 1 """ And the stderr should contain : " "" This is Line 1 on STDERR, before sleep 1 This is Line 2 on STDERR, after sleep 1 Enter string 2 from STDERR: String 2 entered: My String 2 """
  • 53.
  • 54. Works on any OS
  • 55.
  • 56. No easy way to test for lines sequence between stdout and stderr flows
  • 57.
  • 64. Aruba (used with Cucumber ) This presentation is available under CC-BY license by Muriel Salvan
  • 65. Q/A