Questions tagged [qx]

Used for the Perl qx// operator which executes a command and captures the output. The question should always have the Perl tag too.

See the Perl Quote-like operators manual pages for the details. The string between the markers (conventionally two slashes) is executed and the standard output from the command is captured. In a list context, each line is separate; in a scalar context, the whole output is captured as a single string.

20 questions
12
votes
2 answers

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,…
Jonas Wagner
  • 358
  • 3
  • 10
9
votes
9 answers

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…
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
6
votes
3 answers

use perl's qx{} / `...` operator with a list of arguments

system, exec, open '|-', open2, etc. all allow me to specify the command to run as a list of arguments that will be passed directly to execvp instead of run through a shell. Even if perl is smart enough to run it directly if it looks like a "simple"…
user10678532
3
votes
3 answers

How to use __FILE__ inside qx?

I'm trying to assign a constant at the top of a Perl script like so: use constant { # ... CONSTNAME => qx{readlink -e __FILE__} || __FILE__, # ... }; __FILE__ does not get interpolated inside the qx operator, which causes this to fail. How…
0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
3
votes
2 answers

Fork in perl but get exit status from a system call in the child process

What I do: Make an ajax call to a cgi script. Cgi script forks but the parent returns right away with a response msg. The child does a system call but needs the exit code and any error messages. Pseudo-code: $SIG{CHLD} = ‘IGNORE’; # or…
Wilderness
  • 1,309
  • 2
  • 15
  • 27
2
votes
2 answers

Why does perl qx hang in Mojolicious::Lite but not in an ordinary program?

(This is cperl 5, version 24, subversion 4 (v5.24.4c) built for x86_64-linux) Ubuntu 18.04. Below is a program that works. However, when I run this program from within Mojolicious::Lite (version 6.04), it hangs. Using top, I see that "tr" is the one…
ftumsh
  • 89
  • 5
2
votes
1 answer

Perl qx() command not working as expected

I have a perl script as below, where I want to access a network path on a remote windows machine from a linux machine using rsh. $cmd = "rsh -l $username $host \"pushd \\\\network\\path\\to\\the\\directory && dir\""; print $cmd, "\n"; print…
him
  • 487
  • 3
  • 12
2
votes
1 answer

Modules inherited by child process from parent process in Perl

I am integrating a logging framework to my perl project which has around 300 Perl files. So I have written a module Logging.pm which has overridden die , say , warn functionalities and since print cannot be overridden I have tied it my custom…
Dinesh Gowda
  • 1,044
  • 3
  • 13
  • 29
2
votes
2 answers

Unable to complete a command from prompt line, using qx in Perl

I need my perl program to execute a DIR command in the windows command line. I use these lines: $percorso1= C:\PerlEsercitazione\FileCompare1\VSS\Divina Cömmediä\ProgettoTest my $cmd_string = "dir /ad /b ".$percorso1 ; my @result = qx {$cmd_string};…
Maurizio
  • 139
  • 10
2
votes
3 answers

Perl using find in qx

III am writing a Perl script that will need to SSH out to numerous remote servers to perform some gzipping of log files. In the following line, I keep receiving this error and am struggling to determine what's causing this. The error I'm getting…
Skittles
  • 2,866
  • 9
  • 31
  • 37
2
votes
1 answer

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

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…
sid_com
  • 24,137
  • 26
  • 96
  • 187
1
vote
5 answers

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…
chappar
  • 7,275
  • 12
  • 44
  • 57
1
vote
1 answer

Are environment variables preserved through qx in a perl script

I have some legacy perl script, which sets environment variable $ENV{"ENV_VAR_NAME"} = $envVar; and then uses qx() to execute another shell command $command = "$xyz"; $result = qx($command); Will the modified ENV_VAR_NAME be available when qx…
samairtimer
  • 826
  • 2
  • 12
  • 28
1
vote
1 answer

Perl 5.8 Get Stdout from SSH command

I need to create a script that will work on CentOS 5.x and CentOS 6.x boxes. CentOS 5.x uses Perl 5.8 and CentOS 6.x uses Perl 5.10. The goal is to be able to ssh into a box, that has a key exchange in place, then run python -V, to determine if the…
James Oravec
  • 19,579
  • 27
  • 94
  • 160
1
vote
2 answers

Is it possible to call a function within qx?

Here's a bit of Perl code that does what I want: my $value = get_value(); my $result = qx(some-shell-command $value); sub get_value { ... return ... } Is it possible to achieve the same effect without using $value? Something like my…
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
1
2