Advertisement
Guest User

open demo

a guest
Aug 2nd, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. # will use this to find out whether the command received the input
  2. bash-4.1$ cat iotest.sh
  3. #!/bin/bash
  4. read -t 1 in
  5. out="$RANDOM"
  6. echo "TEST INPUT $in" >&2
  7. echo "TEST OUTPUT $out" >&2
  8. echo "$out"
  9.  
  10. # with "|" in front, input can be sent to the command, but command's output can not be read
  11. bash-4.1$ perl -e 'open F,"|./iotest.sh";$out=rand;$in=<F>;print F"$out\n";close F;print"PERL INPUT $in\nPERL OUTPUT $out\n"'
  12. TEST INPUT 0.129122755098255
  13. TEST OUTPUT 26687
  14. 26687
  15. PERL INPUT
  16. PERL OUTPUT 0.129122755098255
  17.  
  18. # "|-" mode string is similar with above
  19. bash-4.1$ perl -e 'open F,"|-","./iotest.sh";$out=rand;$in=<F>;print F"$out\n";close F;print"PERL INPUT $in\nPERL OUTPUT $out\n"'
  20. TEST INPUT 0.261993898618133
  21. TEST OUTPUT 27450
  22. 27450
  23. PERL INPUT
  24. PERL OUTPUT 0.261993898618133
  25.  
  26. # with "|" behind, output can be read from the command, but the command can not get input
  27. bash-4.1$ perl -e 'open F,"./iotest.sh|";$out=rand;$in=<F>;print F"$out\n";close F;print"PERL INPUT $in\nPERL OUTPUT $out\n"'
  28. TEST INPUT
  29. TEST OUTPUT 18103
  30. PERL INPUT 18103
  31.  
  32. PERL OUTPUT 0.571054091750742
  33.  
  34. # "-|" mode string is similar with above
  35. bash-4.1$ perl -e 'open F,"-|","./iotest.sh";$out=rand;$in=<F>;print F"$out\n";close F;print"PERL INPUT $in\nPERL OUTPUT $out\n"'
  36. TEST INPUT
  37. TEST OUTPUT 23718
  38. PERL INPUT 23718
  39.  
  40. PERL OUTPUT 0.985680787664936
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement