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).
ta. Loothi.#!/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"; } }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |