I have an external program I am required to use to issue SQL statements to a database. The way the query works is that I issue a statement and when the result set changes, the program will dump back out to stdout. This keeps me from having to poll the database. I don't have direct access to the DB (that would be preferable) so I'm stuck with this.

The shell command looks like this:

MyDbQueryProgram "SELECT * FROM MY_TABLE;"

It runs fine from the command line, but I'm having a bear of a time getting it to work from POE. Any ideas on how to escape the string here? POE::Wheel::Run does a "sh -c" to run the command. Just running from the shell, this works:

sh -c 'MyDbQueryProgram "SELECT * FROM MY_TABLE;"'

Does anyone have any ideas? Thanks in advance for your help.

#!/usr/bin/perl use warnings; use strict; use POE; use POE::Wheel::Run; use POE::Filter::Line; use POE::Filter::Stream; $| = 1; my $outCT = 0; my $program = "MyDbQueryProgram"; my @progargs = ("SELECT * FROM MY_TABLE;"); POE::Session->create( inline_states => { _start => \&startup, stdout => \&stdout, stdin => \&stdin, stderr => \&stderr, } ); POE::Kernel->run(); sub startup { my $heap = $_[HEAP]; my $wheel = POE::Wheel::Run->new( Program => $program, ProgramArgs => \@progargs, StdinEvent => 'stdin', StderrEvent => 'stderr', StdoutEvent => "stdout", StdoutFilter => POE::Filter::Stream->new(), ); print "Wheel ID is ".$wheel->ID."\n"; print "Wheel's PID is ".$wheel->PID."\n"; $heap->{program} = $wheel; } sub stdout { my ($heap, $input, $wheelID) = @_[HEAP, ARG0, ARG1]; print "$input\n"; $outCT++; print $outCT; } sub stderr { my ($op, $errnum, $errstr, $wheel_id) = @_[ARG0, ARG1, ARG2, ARG3]; print "stderr\n"; print "OP = $op\nERRNUM = $errnum\nERRSTR = $errstr\nID = $wheel_id\n +"; } sub stdin { print "stdin\n"; }

In reply to database query with POE::Wheel::Run by former33t

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.