Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling empty argument to CommandLine in Commons Exec
    primarykey
    data
    text
    <p>I am trying to execute a bash script that takes 3 parameters from Java, following is the code where I create the command line</p> <pre><code>CommandLine command = new CommandLine(/bin/bash); command.addArgument(ScriptName); command.addArgument(Param1); command.addArgument(Param2); command.addArgument(Param3); </code></pre> <p>This works like a charm when I have non empty parameters being passed. But does not work as supposed to the one of the parameter is empty (i.e. "")</p> <p>To elaborate, in some cases Param2 = "". Now when the bash script is executed, instead of considering Param2 = "", it takes Param2 = Param 3 (value) and Param3 = undefined.</p> <p>How do I stop this from happening?</p> <p>Edit: Param1, Param2 &amp; Param3 are actually files names that are passed to the bash script. Where, Param1 => File1, Param2 => File 2 &amp; Param3 => Output File</p> <p>Bash script is actually calling and generating some metrics on the File 1 and storing it in Output File. When generating the metrics there are 2 categories of metrics that are being generated. </p> <ol> <li>Absolute</li> <li>Relative</li> </ol> <p>Absolute are generate on File 1 while the relative are generated after comparing File 1 &amp; File 2. In the bash script I have condition there if the File 2 is not passed in as an argument, do not generate relative metrics.</p> <p>This is what the design has been. Now problems comes in when there is no File 2 present for comparison in which case I want the absolute metrics to be generated and Relative ones to be left out.</p> <p>But right now whats happening with me is Param 3 (i.e. is the output file) is considered as the File 2 (which is completely undesired) and my relative metric generation goes for a toss.</p> <p>When using Runtime.getRuntime().exec i was able to do this by quoting it. i.e. /bin/bash Script Param1 "" Param3 this worked like a charm then.</p> <p>In my attempt to reduce the code and have good cross-platform support I introduced commons-exec and and the problem started appearing.</p> <p>So, My question still is, How do I pass and empty value for Param2 to bash script using commons-exec CommandLine?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload