Hiya.

Messing about with this module IO::CaptureOutput.

I want to do a mysqldump and redirect the raw SQL through gzip. I used to do this with the system command

system("mysqldump --add-drop-table -h $global_host -u $user -p'".$pass."' $db_name  | gzip > $backup_file")

...but if the mysqldump fails, I was still getting a success exit code so I thought I'd split it into the two commands so it's more robust for debugging. Is this method below a decent way to do this? I haven't written any code in ages and am wondering if anyone can check this for me (just the concept, as it's just a snippet and I'd use strict etc in the real script).

#!/usr/bin/perl use IO::CaptureOutput qw/capture_exec capture/; sub mysqldump { system('mysqldump --add-drop-table -h localhost -u myuser -pmypass + mydb '); } capture \&mysqldump, undef, \$stderr, 'outfile.sql'; if ($stderr) { print "FAILED: $stderr\n"; }else{ @args = ('gzip','outfile.sql'); ($stdout, $stderr, $success, $exit_code) = capture_exec(@args) +; if (!$success) { print "Failed gzip: $stderr\n"; } else { print "Success gzip\n"; } }
ta. Loothi.

In reply to Appropriate usage of IO::CaptureOutput for a mysqldump and gzip? by loothi

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.