RexOps/Rex

Error executing commands with space in their full path

Open

#1.401 aberto em 19 de ago. de 2020

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)Perl (218 forks)batch import
bughelp wanted

Métricas do repositório

Stars
 (671 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

Describe the bug

If there's a space in the full path of a command, execution via run() fails with:

[2020-08-19 13:12:48][<local>]  ERROR Error executing: /tmp/path with space/hello.
STDOUT:

STDERR:
sh: /tmp/path: No such file or directory at /home/ferki/perl5/perlbrew/perls/ferki/lib/site_perl/5.32.0/Rex/Commands/Run.pm line 326.

This kind of error may be more apparent on Windows, where calling can_run() returns the full path of the executable, which is often under C:\Program Files, which has a space in it.

Without looking into it more closely, it might be a shell quoting issue.

How to reproduce it

Steps to reproduce the behavior:

  1. Create a path with space(s) in it

    mkdir -p /tmp/path\ with\ space
    
  2. Create an executable under that path, e.g. named hello:

    #!/bin/bash
    echo hello
    
  3. Run that command with rex: rex -e 'my $command = "/tmp/path with space/hello"; say run $command'

Shortest code example that demonstrates the bug: see above

Expected behavior

Rex should be able to execute a command even if its full path contains spaces (or possibly other special characters).

Circumstances

  • Rex version: 1.12.1
  • Perl version: 5.32.0
  • OS running rex: Gentoo
  • OS managed by rex: local/Gentoo

Debug log

Relevant excerpt is the following:

[2020-08-19 13:29:14][<local>]  DEBUG Executing eval-line
[2020-08-19 13:29:14][<local>]  DEBUG Executing: export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/pkg/bin:/usr/pkg/sbin ; LC_ALL=C /tmp/path with space/hello
[2020-08-19 13:29:14][<local>]  DEBUG ========= ERR ============
[2020-08-19 13:29:14][<local>]  DEBUG sh: /tmp/path: No such file or directory

[2020-08-19 13:29:14][<local>]  DEBUG ========= ERR ============

Guia do colaborador