I need to execute Linux command like this using Runtime.getRuntime().exec() :
/opt/ie/bin/targets --a '10.1.1.219 10.1.1.36 10.1.1.37'
Basically, this command is to connect each targets to server one by one (10.1.1.219, 10.1.1.36, 10.1.1.37). It works well in terminal, the result should be :
['10.1.1.219', '10.1.1.36', '10.1.1.37']
But if I execute the command using Runtime.getRuntime().exec(execute), like this :
execute = "/opt/ie/bin/targets" + " " + "--a" + " " + "'" + sb
+ "'";
Java will treat the single quote as string to execute, the result will be :
callProcessWithInput executeThis=/opt/ie/bin/targets --a '10.1.1.219 10.1.1.36 10.1.1.37'
The output for removing undesired targets :["'10.1.1.219"]
Anyone knows how to solve it? Thanks!
exec()and pass each argument as a separate string.