user3189761
user3189761

Reputation: 140

Adb Shell InputText too long

I've this application into which the input text is passed through adb shell , now the problem is whenever i type command :

./adb shell input text 'Khay'

works perfectly fine and it display<"Khay"> it in a text-box in the application as it is supposed to be . but when i pass command that is very long something like :

./adb shell input text ' http://stagingapi.something.com/v2/api.php?apikey=2323214\&appid=32432\&imei=324234 ........................................................

is the text is this much longer it gives me an error

error:service name too long.

now i've a 2part questions.

  1. can i somehow pass this long text using adb shell .

  2. If option1 is not possible then what is it that i can do about passing this long input text

Upvotes: 3

Views: 5947

Answers (2)

Ben
Ben

Reputation: 158

A work around for the problem is to write the long command to a local shell file, push the file using adb push and then execute it on the device using sh.

So instead of executing:

adb shell input text ' http://...some.really.long.command...'

Do this instead:

echo "input text ' http://...some.really.long.command...'" > longcommand.sh
adb push longcommand.sh /data/local/tmp
adb shell sh /data/local/tmp/longcommand.sh

Upvotes: 6

Jon Goodwin
Jon Goodwin

Reputation: 9153

It's not the string length that is your problem, it is the special character handling.

Best to run your string through a converter (to add escape codes),
there are quite a few characters that input does not like:
<pre>
 ( ) < > | ; & * \ ~ 
</pre>
and space escaped with %s .
<pre>
    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;
}

(code from inputer native binary: interactive converter for input).

Upvotes: 1

Related Questions