我们如何能够执行从我的Andr​​oid应用程序shell脚本文件? [英] How can we execute a shell script file from my Android Application?

查看:114
本文介绍了我们如何能够执行从我的Andr​​oid应用程序shell脚本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的Andr​​oid应用程序中执行shell脚本。

I am trying to execute a shell script from my Android application.

首先,我试图从Java运行shell脚本,它做工精细的所有命令 如 PWD 光盘的netstat 。移动文件,复制文件。

First I tried to run Shell script from Java ,and it working fine for all commands like pwd, cd , netstat. moving the file ,copying the file.

比我从一个Android应用程序尝试过了,我得到输出光盘 PWD 的netstat 并为那些在脚本中echo语句,但对于移动和复制文件无法正常工作。

Than I've tried it from an Android application and I'm getting output for cd ,pwd, netstat and for echo statements that are in script, but for moving and copying the file are not working.

是否有任何权限需要从脚本文件执行这些命令,这些命令都工作正常,亚行的shell?

Are any Permissions needed to execute these commands from the script file while these commands are working fine from adb shell?

我的code是这样的:

my code look like this:

void execCommandLine()
    {
       //***********************
        try
        {
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec("ls -all");

            proc = rt.exec("sh /data/shTest.sh");
            InputStream is = proc.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;

       while ((line = br.readLine()) != null) {
         System.out.println(line);
       }
           } catch (Throwable t)
          {
            t.printStackTrace();
          }

和我的脚本文件如下所示:

and my script file is as follows:

#!/bin/sh
echo "Knowledge is Power"
echo "I am a script"
echo $PATH
netstat
pwd
cd /data
pwd
cd /system/bin
pwd
  mv  /data/local/hello.txt /data/
  cp  /data/local/hello1.txt /data/
cd /data/local/tmp
cd /system/bin

只有 CP MV 命令没有显示预期的结果。 请给我一些指导。

Only the cp and mv commands are not showing expected result. Please give me some guidance.

第一件事,我想和测试它变成模拟器。在/系统/ bin中有MV commond,我也试图与busybox的,但我没有得到预期的结果。对于root权限。如何proceed..Give一些想法进行。

First thing I am trying and testing it into Emulator. In /system/bin have mv commond and I have also tried with busybox but I didnt get expected result. For root privilage how to proceed..Give some idea to proceed.

推荐答案

MV CP 这两个给我捣乱在android外壳。许多人使用催化剂×>是或体面的结果类似。

mv and cp both give me trouble in the android shell. many other people use cat x > y or similar with decent results.

这篇关于我们如何能够执行从我的Andr​​oid应用程序shell脚本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆