Post Reply

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

27th May 2014, 11:07 PM   |  #1  
OP Member
Flag Kavaratti
Thanks Meter: 238
 
91 posts
Join Date:Joined: May 2014
More
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..
Last edited by sabeersas; 28th May 2014 at 03:15 PM.
28th May 2014, 12:45 AM   |  #2  
Senior Member
Thanks Meter: 45
 
226 posts
Join Date:Joined: 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
28th May 2014, 04:21 AM   |  #3  
OP Member
Flag Kavaratti
Thanks Meter: 238
 
91 posts
Join Date:Joined: May 2014
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, 12:45 PM   |  #4  
OP Member
Flag Kavaratti
Thanks Meter: 238
 
91 posts
Join Date:Joined: May 2014
More
Thumbs up Fixed
I fixed it.... here is the complete code which escape space and all the special characters..

Code:
string.replaceAll("(?=[]\\[+&|!(){}^\\s\'\";~*?:\\\\-])", "\\\\");
Last edited by sabeersas; 29th May 2014 at 03:29 PM. Reason: code updated
The Following User Says Thank You to sabeersas For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank