You're looking for the "open()" command here, which can be used to open streams to processes as well as normal files. Instead of using "<" or ">" to indicate what direction to open a stream (for input or output), use "-|" to read from a process or "|-" to write to it. In place of the filename, just provide the program to execute. In your case:
Code:
open($fh, "-|", "fdisk -l")
And then just read from the $fh filehandle like you normally would. You can even slurp it all up into a variable if you want.
An easier, but less flexible, alternative is the "readpipe()" command. It takes a single scalar parameter - the program to execute. In scalar context it returns a single, possibly multiline string with all the output of that program. In list context it returns a list of strings, each one line from the program's output. Again, in your example:
Code:
my $output = readpipe("fdisk -l")