qx

How can I change the standard output filehandle for a system call in Perl?

I am trying change the stdout of the system function using select. But it does not seem to be working. The system output is getting displayed on console rather than getting redirected to the file. use strict; use warnings; chdir "C:\\Documents and Settings\\" or die "cannot open the dir\n"; open FH, ">out.txt" or die "cannot open out.t...

How do I get the output of curl into a variable in Perl if I invoke it using backtics?

I'm trying to get the response of a curl call into a variable in perl. my $foo = `curl yadd yadda`; print $foo; does not work. When I run this at the command line the curl call prints all its output correctly in the terminal, but the variable is not filled with that data. Is there a way to do this without installing and calling th...

How can I implement a timeout for a qx(command)?

Hello! How could I implement in this piece of code a timeout: if the "hwinfo --usb"-command didn't return anything after a certain amount of time, ( stop the command and ) do a return or die from the sub _usb_device. #!/usr/bin/env perl use warnings; use strict; sub _usb_device { my @array; { local $/ = ""; @array = q...

How do I mock Perl's built-in backticks operator?

I'd like to unit test a Perl program of mine that is using backticks. Is there a way to mock the backticks so that they would do something different from executing the external command? Another question shows what I need, but in Ruby. Unfortunately, I cannot choose to use Ruby for this project, nor do I want to avoid the backticks. ...