FORUMS
Remove All Ads from XDA

[Q] [SOLVED]Escape Space and Special Characters in Shell Command

94 posts
Thanks Meter: 305
 
Post Reply Email Thread
Hai... I developing a root access app using RootTools library .... When I copy file using CAT command ... it is not working if the file path has space or any special character... please help me to escape space and special characters or tell any other better solution....

Thanks in Advance..
 
 
28th May 2014, 01:45 AM |#2  
Senior Member
Thanks Meter: 142
 
More
Maybee something like this:

private static final String UNIX_ESCAPE_EXPRESSION = "(\\(|\\)|\\[|\\]|\\s|\'|\"|`|\\{|\\}|&|\\\\|\\?)";

/**
* Adds escaping. Used for file paths.
*
* @param input Input command line param
* @return input string with escaped characters
*/
public static String getCommandLineString(String input) {
return input.replaceAll(UNIX_ESCAPE_EXPRESSION, "\\\\$1");
}

Gesendet von meinem K00C mit Tapatalk
28th May 2014, 05:21 AM |#3  
OP Member
Flag Kavaratti
Thanks Meter: 305
 
More
Quote:
Originally Posted by tschmid

Maybee something like this:

private static final String UNIX_ESCAPE_EXPRESSION = "(\\(|\\)|\\[|\\]|\\s|\'|\"|`|\\{|\\}|&|\\\\|\\?)";

/**
* Adds escaping. Used for file paths.
*
* @param input Input command line param
* @return input string with escaped characters
*/
public static String getCommandLineString(String input) {
return input.replaceAll(UNIX_ESCAPE_EXPRESSION, "\\\\$1");
}

Gesendet von meinem K00C mit Tapatalk

Thanks for the help bro....but still its not working... I got another regex to escape all the special characters and it works... will you please add space escape to the below regex...

Code:
replaceAll("(?=[]\\[+&|!(){}^\"~*?:\\\\-])", "\\\\");
28th May 2014, 01:45 PM |#4  
OP Member
Flag Kavaratti
Thanks Meter: 305
 
More
Thumbs up Fixed
I fixed it.... here is the complete code which escape space and all the special characters..

Code:
string.replaceAll("(?=[]\\[+&|!(){}^\\s\'\";~*?:\\\\-])", "\\\\");
The Following User Says Thank You to sabeersas For This Useful Post: [ View ] Gift sabeersas Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes