When I do enter some text with & character then my complete text is not entered on the device.
D:\Apps\Android-SDK\tools>adb shell input text hello&hello
'hello' is not recognized as an internal or external command,
operable program or batch file.
It entered only hello
. but the other &
and hello
characters are not entered.
How can I enter the & character?
You need to encapsulate your string in quotes and escape your ampersand "hello\&hello"
( ) < > | ; & * \ ~ " '
and space all need escaping.
Space can be replaced with %s
.
I have written an android command line tool to do this call inputer
.
A function from my code is here (uses regex
):
//e.g. convert string "hello world\n" to string "hello%sworld\n"
char * convert(char * trans_string)
{
char *s0 = replace(trans_string, '\\', "\\\\");
free(trans_string);
char *s = replace(s0, '%', "\\\%");
free(s0);
char *s1 = replace(s, ' ', "%s");//special case for SPACE
free(s);
char *s2 = replace(s1, '\"', "\\\"");
free(s1);
char *s3 = replace(s2, '\'', "\\\'");
free(s2);
char *s4 = replace(s3, '\(', "\\\(");
free(s3);
char *s5 = replace(s4, '\)', "\\\)");
free(s4);
char *s6 = replace(s5, '\&', "\\\&");
free(s5);
char *s7 = replace(s6, '\<', "\\\<");
free(s6);
char *s8 = replace(s7, '\>', "\\\>");
free(s7);
char *s9 = replace(s8, '\;', "\\\;");
free(s8);
char *s10 = replace(s9, '\*', "\\\*");
free(s9);
char *s11 = replace(s10, '\|', "\\\|");
free(s10);
char *s12 = replace(s11, '\~', "\\\~");
//this if un-escaped gives current directory !
free(s11);
char *s13 = replace(s12, '\¬', "\\\¬");
free(s12);
char *s14 = replace(s13, '\`', "\\\`");
free(s13);
// char *s15 = replace(s14, '\¦', "\\\¦");
// free(s14);
return s14;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With