/IOU/Proj00/scripts/wrapper.pl

https://github.com/JoseIbanez/testing · Perl · 115 lines · 56 code · 35 blank · 24 comment · 7 complexity · 79e5f9068ae0b83954d587e55cf75166 MD5 · raw file

  1. #!/usr/bin/perl
  2. use strict 'vars';
  3. use File::Basename;
  4. use Getopt::Long;
  5. use IO::Socket;
  6. use POSIX qw(:sys_wait_h);
  7. use IO::Select;
  8. my $version = "0.1"; # wrapper-linux version
  9. my $image; # storing IOU full image name (e.g. /opt/iou/bin/I86BI_LINUX-IPBASE-M-12.4)
  10. my $port; # storing telnet port (e.g. 2001)
  11. my $path; # storing IOU running path (e.g. /opt/iou/bin)
  12. my $iou_pid; # pid for iou process
  13. sub main::HELP_MESSAGE {
  14. print STDERR "Usage: splice [-a arch] [-e exclude_file] [-l log_file] [-r] DIR...\n\n";
  15. print STDERR "Repositories should be listed in increasing priority order\n";
  16. print STDERR " -a <arch> Target different arch than this host\n";
  17. print STDERR " -e <file> Exclude keys listed in this file\n";
  18. print STDERR " -l <file> Write comprehensive log to file\n";
  19. print STDERR " -n No new keys. Build package list from root repo only\n";
  20. print STDERR " -r Replace only mode. Don't upgrade to later versions.\n";
  21. }
  22. sub main::VERSION_MESSAGE {
  23. print "version\n";
  24. }
  25. sub REAPER {
  26. 1 until (-1 == waitpid(-1, WNOHANG));
  27. $SIG{CHLD} = \&REAPER; # unless $] >= 5.002
  28. }
  29. # Getting options (m = IOU image, p = telnet port, @ARGV = IOU options)
  30. GetOptions (
  31. 'm=s' => \$image,
  32. 'p=i' => \$port,
  33. );
  34. $path = dirname($image);
  35. print "Starting IOU: $image @ARGV\n";
  36. use IPC::Open3;
  37. #my($chld_out, $chld_in, $chld_err);
  38. #$iou_pid = open3(\*WRITER, \*READER, \*ERROR, "cd $path; $image @ARGV");
  39. #$iou_pid = open3(\*WRITER, \*READER, \*ERROR, "/bin/bash");
  40. #my $pid = open3(\*WRITE, \*READ,\*ERROR,"/bin/bash");
  41. my $iou_pid = open3(\*WRITE, \*READ,\*ERROR,"cd $path; $image @ARGV");
  42. #if \*ERROR is false, STDERR is sent to STDOUT
  43. my $selread = new IO::Select();
  44. my $selerror = new IO::Select();
  45. my $selwrite = new IO::Select();
  46. $selread->add(\*READ);
  47. $selerror->add(\*ERROR);
  48. # may not be best use of IO::Select, but it works :-)
  49. my($error,$answer)=('','');
  50. while(1){
  51. print "Enter expression for bc, i.e. 2 + 2\n";
  52. chomp(my $query = <STDIN>);
  53. #send query to bc
  54. print WRITE "$query\n";
  55. #timing delay needed tp let bc output
  56. select(undef,undef,undef,.01);
  57. #see which filehandles have output
  58. if($selread->can_read(0)){print "ready->read\n"}
  59. if($selerror->can_read(0)){print "ready->error\n"}
  60. #get any error from bc
  61. sysread(ERROR,$error,4096) if $selerror->can_read(0);
  62. if($error){print "\e[1;31m ERROR-> $error \e[0m \n"}
  63. #get the answer from bc
  64. sysread(READ,$answer,4096) if $selread->can_read(0);
  65. if($answer){print "$query = $answer\n"}
  66. ($error,$answer)=('','');
  67. }
  68. waitpid($iou_pid, 1);
  69. # It is important to waitpid on your child process,
  70. # otherwise zombies could be created.
  71. # It is important to waitpid on your child process,
  72. # otherwise zombies could be created.
  73. #open(IOU, "cd $path; $image @ARGV |") || die "Failed: $!\n";
  74. #while (<IOU>) {
  75. # print;
  76. #}
  77. # http://perldoc.perl.org/perlipc.html#Using-open()-for-IPC
  78. # Complete Dissociation of Child from Parent
  79. #open(IOU, "cd $path; $image @ARGV |") || die "Failed: $!\n";
  80. exit 0;