I'm having problem separating two string variables as arguments for a bash script. My bash script takes two arguments like so:
#!/bin/bash
DATA1=$1
DATA2=$2
However, DATA1 and DATA2 are not what I intended, because bash is reading my strings wrongly. DATA2 is only the first part of the argument I wanted to put in, because I'm having trouble making a complicated(relatively) string into a single arguemnt.
I call this script from a Java app with variables like this:
String m1 = "some data";
String m2 = "some more"+mystring+"even more data"+anotherstring;
myscript.sh m1 m2
Only the first part of m2 is passed to DATA1 in the bash script. I've tried wrapping the whole thing in single quotes and double quotes I can't get it to accept the whole of m2 as the second argument.
Any help in creating two string arguments is appreciated.
Runtime.exec()
?, ProcessBuilder
?), including the code that sets up the arguments. Otherwise we're just guessing - Jim Garrison 2012-04-04 03:55
It works for me, see:
Runtime.getRuntime().exec(new String[]{"/bin/sh", "/tmp/myscript.sh", m1,m2});
Your code calls:Runtime.getRuntime().exec(String)
It calls method exec(command,null,null)
(see source code in src.zip) exec(String command, String[] envp, File dir) .
Method exec(String command, String[] envp, File dir) parse command by StringTokenizer. So text "some data"
or "\"some data\""
is split to some
data
(or "some
data "
)