Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Adb Shell输入文本太长_Android_Shell_Adb - Fatal编程技术网

Android Adb Shell输入文本太长

Android Adb Shell输入文本太长,android,shell,adb,Android,Shell,Adb,我在这个应用程序中输入文本是通过adb shell传递的,现在的问题是每当我键入命令时: ./adb外壳输入文本“Khay” 它工作得非常好,并按预期在应用程序的文本框中显示它。但当我传递一个很长的命令时,比如: ./adb shell input text ' http://stagingapi.something.com/v2/api.php?apikey=2323214\&appid=32432\&imei=324234 ..........................

我在这个应用程序中输入文本是通过adb shell传递的,现在的问题是每当我键入命令时:

./adb外壳输入文本“Khay”

它工作得非常好,并按预期在应用程序的文本框中显示它。但当我传递一个很长的命令时,比如:

./adb shell input text ' http://stagingapi.something.com/v2/api.php?apikey=2323214\&appid=32432\&imei=324234 ........................................................
文本是否长了这么多?它给了我一个错误

错误:服务名称太长

现在我有两个问题

  • 我可以用adb shell传递这个长文本吗

  • 如果选项1不可能,那么我可以做什么来传递这个长输入文本


  • 解决此问题的方法是将long命令写入本地shell文件,使用
    adb push
    推送该文件,然后使用
    sh
    在设备上执行该命令

    因此,与其执行:

    adb shell input text ' http://...some.really.long.command...'
    
    改为这样做:

    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
    

    问题不是字符串长度,而是特殊的字符处理

    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).
    
    最好通过转换器运行字符串(添加转义码),
    有相当多的字符是input不喜欢的:
    ( ) < > | ; & * \ ~ 
    空间与%s一起转义。
    字符*转换(字符*转换字符串)
    {
    char*s0=replace(trans\u字符串,'\\',“\\\\”;
    自由(trans_字符串);
    char*s=replace(s0,“%”,“\\\%”);
    免费(s0);
    char*s1=replace(s,,“%s”);//空格的特殊情况
    免费的;
    char*s2=replace(s1,“\\”,“\\\”);
    免费(s1);
    char*s3=替换(s2,'\'','\\''');
    免费(s2);
    char*s4=替换(s3,“\\(”,“\\\(”);
    免费(s3);
    字符*s5=替换(s4,“\”,“\ \”)”;
    免费(s4);
    字符*s6=替换(s5,“\\&”、“\\\&”);
    免费(s5);
    char*s7=替换(s6,“\\”,“\\\>”);
    免费(s7);
    char*s9=替换(s8,“\;”,“\\\;”;
    免费(s8);
    char*s10=替换(s9,“\*”,“\\\*”;
    免费(s9);
    char*s11=替换(s10,“\\\\”,“\\\\\”);
    自由(s10);
    char*s12=替换(s11,“\~”,“\\\~”;
    //如果未转义,则给出当前目录!
    免费(s11);
    字符*s13=替换(s12,“\\”,“\\”);
    免费(s12);
    char*s14=替换(s13,“\`',“\\\`”);
    免费(s13);
    //字符*s15=替换(s14,“\\\\”,“\\\”);
    //免费(s14);
    返回s14;
    }
    (来自inputer本机二进制代码:用于输入的交互式转换器)。
    
    确保文本字符串不包含空格。用
    %s
    替换所有空格是的,我也已经这样做了。我想出了一个临时而简单的解决方案,将输入分为三部分传递,字符串只需将一部分附加到另一部分,这救了我的命。我不想根目录我的设备,也不记得我可以
    sh file.sh
    而不是
    /file.sh
    。只需一句话:我认为这不需要
    chmod+x file.sh
    ,因为您没有直接运行脚本。如果您想自己运行它,则需要使其可执行,尽管在这种情况下,您需要在开始时使用shebang语句。