Error executing commands with space in their full path
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 737
- Forks
- 214
- PR merge metrics
- No merged PRs in 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:
-
Create a path with space(s) in it
mkdir -p /tmp/path\ with\ space -
Create an executable under that path, e.g. named
hello:#!/bin/bash echo hello -
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 ============
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with Rex/Commands/Run.pm at line 326 and trace how run() invokes the shell. Reproduce the documented /tmp/path with space/hello command, then check the can_run() case mentioned for Windows. Done means run() executes commands whose full paths contain spaces successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100