Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,785,193 Members 36,781 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
sabeersas
Old
(Last edited by sabeersas; 28th May 2014 at 03:15 PM.)
#1  
Member - OP
Thanks Meter 229
Posts: 90
Join Date: May 2014
Location: Kavaratti
Default [Q] [SOLVED]Escape Space and Special Characters in Shell Command

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..
 
tschmid
Old
#2  
Senior Member
Thanks Meter 26
Posts: 158
Join Date: Feb 2013
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
 
sabeersas
Old
#3  
Member - OP
Thanks Meter 229
Posts: 90
Join Date: May 2014
Location: Kavaratti
Quote:
Originally Posted by tschmid View Post
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("(?=[]\\[+&|!(){}^\"~*?:\\\\-])", "\\\\");
 
sabeersas
Old
(Last edited by sabeersas; 29th May 2014 at 03:29 PM.) Reason: code updated
#4  
Member - OP
Thanks Meter 229
Posts: 90
Join Date: May 2014
Location: Kavaratti
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: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes