Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

ipc::run3 portability

by murrayn (Sexton)
on Feb 03, 2017 at 02:48 UTC ( [id://1180917]=perlquestion: print w/replies, xml ) Need Help??

murrayn has asked for the wisdom of the Perl Monks concerning the following question:

I have a Perl script which should run on Windows, Linux or proprietary Unix systems (subject to the proprietary OS vendors providing a moderately current Perl environment!).

I am building a command ARRAY comprising the command name followed by a series of -keyword value pairs:

@cmd = (@cmd, "-key1", "value", "-key2", "value2");

This process works happily when I run it on Windows (10, Server 2012) and on Linux (CentOS 7) UNLESS one of the values is blank (a literal space character). If I code

@cmd = (@cmd, "-key1", " ", "-key2", "value2");

Windows handles this correctly and passes the space as the value of key1 but Linux attempts to pass "-key2" as the value of key1 and the invoked command suffers fatal conniptions!

If I place single or double quotes around the space character, both platforms object to receiving "' '" since the application expects either an X or a space (without enclosing quotation marks).

When I copy the failing command line to the Linux shell prompt it fails unless I manually insert a pair of quotes around the space character.

Can anybody advise on how to pass an unquoted space character via ipc::run3 please?

Replies are listed 'Best First'.
Re: ipc::run3 portability
by haukex (Archbishop) on Feb 03, 2017 at 07:21 UTC

    Hi murrayn,

    This process works ... on Linux ... UNLESS one of the values is blank (a literal space character).

    Could you show an SSCCE that reproduces the problem? This program works for me:

    #!/usr/bin/env perl use warnings; use strict; use Data::Dumper; use IPC::Run3 'run3'; if (!@ARGV) { print "IPC::Run3 ver $IPC::Run3::VERSION\n"; print "Calling self ($^X $0) with args...\n"; my @cmd = ($^X,$0); @cmd = (@cmd, "-key1", " ", "-key2", "value2"); run3 \@cmd or die; die if $?; } else { print Dumper \@ARGV; } __END__ IPC::Run3 ver 0.048 Calling self with args... $VAR1 = [ '-key1', ' ', '-key2', 'value2' ];

    The single space gets passed through in @ARGV. Perhaps the problem is on the receiving end? Or you've got an old version of the module? Could you post the output you get from this program here?

    Update: Replaced 'perl' with $^X.

    Regards,
    -- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1180917]
Approved by Paladin
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-28 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found