我需要从用户那里获取Integer输入(来自EditText数字)以使其成为命令行,但是如果我将cmd行改为(“echo 255&gt”,我似乎无法正常工作) ; ...“)它可以工作,但如果我尝试放置用户输入而不是255,则不会。
这是代码。
public class main extends Activity {
EditText value;
int uin;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
value = (EditText) findViewById(R.id.editText2);
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
{
os.writeBytes("mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system\n" +
"exit \n");
os.flush();
process.waitFor();
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
//Button OK
Button bOK = (Button) findViewById(R.id.bOK);
bOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
uin = Integer.parseInt(value.getText().toString());
Process process = null;
try {
process = Runtime.getRuntime().exec("su");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DataOutputStream os = new
DataOutputStream(process.getOutputStream());
try {
os.writeBytes("chmod 644 sys/class/leds/button-backlight/brightness\n");
os.writeBytes("echo" +uin+ "> sys/class/leds/button-backlight/brightness\n");
os.writeBytes("chmod 444 sys/class/leds/button-backlight/brightness\n");
os.writeBytes("exit\n");
os.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 0 :(得分:0)
我的第一个猜测是你缺乏空间。
如果echo 255 > ...
有效,那很好,但使用+
将字符串连接在一起并不会添加隐含空格,因此您的代码目前会生成{{1}如果uin = 255.换句话说,请尝试:
echo255> sys/class...
HTH