scipio
scipio

Reputation: 113

Mixing vboxmanage and bash commands in perl script

I'm using VirtualBox on Ubuntu 12.04 to run virtual machines. I'm trying to execute a VirtualBox command through the CLI, using VBoxManage. I want to capture its output in a text file, so I've written the following:

use warnings;
use strict;
use File::Slurp;

my $vmname = <STDIN>;

system("vboxmanage showvminfo $vmname | > vminfo.txt");
my @vminfo = read_file('vminfo.txt');
print @vminfo;

However, nothing happens. When I open vminfo.txt it is empty. It should contain a lot of info about the VM.

Is it even possible to submit commands like this? I am aware that there could be problems with having vboxmanage as the prefix. Is there a way I can escape that command and submit a bash command on the same line?

Thanks.

Upvotes: 1

Views: 344

Answers (1)

glenn jackman
glenn jackman

Reputation: 246867

You don't need to redirect to a file:

chomp( my @vminfo = `vboxmanage showvminfo $vmname` );

Upvotes: 1

Related Questions