iperf показывает ошибку - iperf [1]: синтаксическая ошибка ')' неожиданная - PullRequest
0 голосов
/ 30 октября 2019

Я успешно скомпилировал код и сгенерировал исполняемый файл. Но когда я пытаюсь выполнить команды в приложении для Android, я получаю сообщение об ошибке iper [1]: синтаксическая ошибка ')' неожиданно . Пожалуйста, предложите любые решения. Заранее спасибо. Я выполнил код в AsyncTask.

@Override
    protected String doInBackground(Void... voids) {
        //Iperf command syntax check using a Regular expression to protect the system from user exploitation.
        String str = inputCommands.getText().toString();
        if (!str.matches("(iperf )?((-[s,-server])|(-[c,-client] ([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5]))|(-[c,-client] \\w{1,63})|(-[h,-help]))(( -[f,-format] [bBkKmMgG])|(\\s)|( -[l,-len] \\d{1,5}[KM])|( -[B,-bind] \\w{1,63})|( -[r,-tradeoff])|( -[v,-version])|( -[N,-nodelay])|( -[T,-ttl] \\d{1,8})|( -[U,-single_udp])|( -[d,-dualtest])|( -[w,-window] \\d{1,5}[KM])|( -[n,-num] \\d{1,10}[KM])|( -[p,-port] \\d{1,5})|( -[L,-listenport] \\d{1,5})|( -[t,-time] \\d{1,8})|( -[i,-interval] \\d{1,4})|( -[u,-udp])|( -[b,-bandwidth] \\d{1,20}[bBkKmMgG])|( -[m,-print_mss])|( -[P,-parallel] d{1,2})|( -[M,-mss] d{1,20}))*"))
        {
            publishProgress("Error: invalid syntax. Please try again.\n\n");
            return null;
        }
        try {
            //The user input for the parameters is parsed into a string list as required from the ProcessBuilder Class.
            String[] commands = inputCommands.getText().toString().split(" ");
            List<String> commandList = new ArrayList<String>(Arrays.asList(commands));
            //If the first parameter is "iperf", it is removed
            if (commandList.get(0).equals((String) "iperf")) {
                commandList.remove(0);
            }
            //The execution command is added first in the list for the shell interface.
            commandList.add(0,"/data/data/com.example.networkcheck/iperf");
            //The process is now being run with the verified parameters.
            process = new ProcessBuilder().command(commandList).redirectErrorStream(true).start();
            //A buffered output of the stdout is being initialized so the iperf output could be displayed on the screen.
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            int read;
            //The output text is accumulated into a string buffer and published to the GUI
            char[] buffer = new char[4096];
            StringBuffer output = new StringBuffer();
            while ((read = reader.read(buffer)) > 0) {
                output.append(buffer, 0, read);
                //This is used to pass the output to the thread running the GUI, since this is separate thread.
                publishProgress(output.toString());
                output.delete(0, output.length());
            }
            reader.close();
            process.destroy();
        }
        catch (IOException e) {
            publishProgress("\nError occurred while accessing system resources, please reboot and try again.");
            e.printStackTrace();
        }
        return null;
    }
@Override
    public void onProgressUpdate(String... strings) {
        tv.append(strings[0]);
        //The next command is used to roll the text to the bottom
        scroller.post(new Runnable() {
            public void run() {
                scroller.smoothScrollTo(0, tv.getBottom());
            }
        });
    }
...