-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] GenericContainer doesn’t properly split commands #5784
Comments
Hi @dhoard, Method signature: void setCommand(@NonNull String... commandParts); Example usage: setCommand("--display=true", "-driver=\"kernel-4.0 kernel-4.1\""); Will this work? |
@hariohmprasath sure, that method is a workaround if the parts are already split. In my scenario, I am reading a complex/quoted command line from a file. Ideally, I should be able to pass the whole command line to The code of |
Hey @dhoard. Thanks for reporting this. This is a valid use case and it's no surprise that users would expect that From an SO post:
I think POSIX based commands are different from DOS based commands. Though, I think it should be fine to assume POSIX based commands as docker containers are linux based. Though, there might be use cases where one might expect to run a DOS based command? I think a bit more time is required to think through this problem. In the meantime, as a workaround - would it be possible to use one of the solutions on this SO post and then passing into the alternate method |
@REslim30 Thanks for the insight. I can see where non-POSIX commands could be a probably. I currently have a workaround in place, so it's not blocking me. |
On the dockerfile docs, there seems to be mention of windows containers:
Windows seems to be a container that you can run that is windows based. Though there are some caveats:
This image has 1M downloads so it is something we should consider. |
I believe Windows containers on windows (WCOW) isn't currently supported on Test containers. That work is currently being done to support it as per #5621. I feel like it would be okay to assume that I feel at this stage we can just provide a basic implementation that supports quotes (and not Really the only difference I've found is support for escaping double quotes.
doesn't work in windows but it does on linux. |
I feel that a better approach than
Example usages:
This would also allow a developer to provide a custom command processor to split commands, replace values in a command, validate command format, build dynamic commands, etc. |
@dhoard I like that suggestion; It's better than the But before going with that approach. I think we should just extend the current |
It actually might be a shell thing. From
|
Sorry for the late reply but something like this should work |
@eddumelendez agreed... and the approach I took. The lack of support for quoted arguments when using Would you accept a Javadoc PR to make this more apparent? |
I think an improvement in our docs make sense. Please, take into account the code snippets in our docs are concentre test examples. PR is welcome :) |
Closing as this one was solved. PR for docs is welcome. |
Module
Core
Testcontainers version
1.17.3
Using the latest Testcontainers version?
Yes
Host OS
ALL
Host Arch
ALL
Docker version
What happened?
GenericContainer
setCommand
uses Java Stringsplit
to build the array of command parts. If the command contains quoted arguments/quoted arguments with escaped quotes, the container fails.Example command:
/bin/sh test.sh “argument 1” “argument 2”
Relevant log output
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: