-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
upload_and_run doesn't separate $command from first arg #1616
Comments
I wonder whether we should use some shellQuoting function for the arguments, so that a single space string, or a string containing two words separated by a space, can be passed as an argument, for example. |
Thanks for the report! Apparent internal usageFirst, I'd say Reproducing the issueSecond, with the provided example, I get use Rex;
use Rex::Helper::Run;
task 'test', sub {
my $output = upload_and_run <<~'BASH', args => ['foo'];
#!/bin/bash
echo $1
BASH
}; With this I could reproduce the issue 👍 I agree that the problem seems to be with a missing space between the command name and its list of arguments passed to it. I also agree if we are going to pass arguments, these should be quoted properly depending on the shell rules of the managed endpoint (this could be done by the user, though we could use Net::OpenSSH::ShellQuoter internally here.) HotfixAn admittedly naive hotfix could be: diff --git a/lib/Rex/Helper/Run.pm b/lib/Rex/Helper/Run.pm
index 20d64b59..2799ba59 100644
--- a/lib/Rex/Helper/Run.pm
+++ b/lib/Rex/Helper/Run.pm
@@ -44,7 +44,7 @@ sub upload_and_run {
}
if ( exists $option{args} ) {
- $command .= join( " ", @{ $option{args} } );
+ $command = join( " ", $command, @{ $option{args} } );
}
return i_run("$command 2>&1"); WorkaroundAlternatively, do the upload and run separately on our own from a task, like: file $my_tmp_file,
content => <<~'BASH',
#!/bin/bash
echo $1
BASH
mode => 0755;
run("$tmp_file foo"); In this case, it may not even have to be a temporary file, but can be deployed normally to Initial thoughts on a fixSince there are currently no tests for Using a test case based on
I expect such a set of tests would fail initially only due to this bug, and a follow-up commit can demonstrate a solid fix. |
Describe the bug
When doing this:
...this produces an error, because it's trying to execute
/tmp/${random_string}.tmpfoo
on the server (observe that there's no space separating the command from the first argument).Expected behavior
$output
should equal the stringfoo
How to reproduce it
Write the code in the bug description inside a task, and see the error being output.
Code example
No response
Additional context
No response
Rex version
1.14.3
Perl version
v5.38.2
Operating system running rex
Void Linux
Operating system managed by rex
Debian
How rex was installed?
package manager
The text was updated successfully, but these errors were encountered: