-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
String array command with SystemCommandTasklet #752
Comments
Mahmoud Ben Hassine commented
SystemCommandTasklet systemCommandTasklet = new SystemCommandTasklet();
systemCommandTasklet.setCommand("/bin/bash");
systemCommandTasklet.setEnvironmentParams(new String[] {"-c", "tshark -i enp1s0 -w ~/Documents/log.pcap -f \"host 8.8.8.8\""}); The array of arguments will be passed as parameters to the command when calling EDIT: The example above is incorrect. SystemCommandTasklet systemCommandTasklet = new SystemCommandTasklet();
systemCommandTasklet.setCommand("/bin/bash -c tshark -i enp1s0 -w ~/Documents/log.pcap -f \"host 8.8.8.8\""); The Javadoc of |
dgray16 commented Mahmoud Ben Hassine thanks! I suggest adding this to https://github.com/spring-projects/spring-batch/tree/master/spring-batch-samples |
Passing command arguments as environment parameters seems counter-intuitive. Does this mean the intent of SystemCommandTasklet#setEnvironmentParams is both command arguments and environment parameters? |
I wouldn't expect that passing command arguments to |
I have ideas for how to support this while maintaining backward compatibility. I also want to do it in a way that works for the requirements in BATCH-2318 |
setCommand now supports passing in an array of strings. When a single string is supplied, it is tokenized by the Runtime#exec method. When an array of strings is supplied, the array is supplied as is to the Runtime#exec method in which case no tokenization takes place. Resolves spring-projects#752
The example in my previous comment is incorrect, I edited that comment to clarify things. Apologies for the confusion. I believe |
setCommand now supports passing in an array of strings. When a single string is supplied, it is tokenized by the Runtime#exec method. When an array of strings is supplied, the array is supplied as is to the Runtime#exec method in which case no tokenization takes place. Resolves spring-projects#752
dgray16 opened BATCH-2863 and commented
Hi. Using this chance I want to thank you for Spring Batch, it is amazing :)
Now, directly to the topic.
I want to use
but there an issue.
There is method:
which accepts
My task is simple: run network packet analyzer Wireshark before processing is started.
Bash command looks like this:
The problem is that
is about to split provided String with Bash command into array, after it command is not working.
In this case helps a lot another method
So if I split manually command into this:
Works perfectly.
If there is tricky way to hack
to make it work with my example, I suggest to add JavaDoc above
If not, I suggest to provide possibility to use both forms, String[] + String.
And one more thing, there may be opportunity to run sh script by single String method (did not test it), but I am not interested in it. I am interested only in hardcoded bash command.
As a workaround for it right now I have written this code:
In any case I am ready to create PR based on discussion here if that will be needed.
Affects: 4.2.1
The text was updated successfully, but these errors were encountered: