小编Mic*_*lle的帖子

通过Android上的Java代码运行Shell命令?

我有一个应用程序应该使用一些shell命令将文件从SD卡复制到/ system/media /.它将需要root,我正在root设备上进行测试.我正在使用运行时来执行shell命令,但它不起作用.这是我的运行时间

public void RunAsRoot{String[] commands = {"sysrw", "rm /data/local/bootanimation.zip", "sysro"};{
    Process p = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(p.getOutputStream());            
    for (String tmpCmd : commands) {
    os.writeBytes(tmpCmd+"\n");
    }           
    os.writeBytes("exit\n");  
    os.flush();
}
Run Code Online (Sandbox Code Playgroud)

但我的logcat只显示其中两个没有被拒绝

07-30 03:14:11.112: WARN/su(3593): request rejected (10047->0 /system/bin/sh)
07-30 03:14:11.132: DEBUG/su(3592): 10047 com.bba.stormdroid executing 0 /system/bin/sh using shell /system/bin/sh : sh
07-30 03:14:11.152: WARN/su(3594): request rejected (0->0 /system/bin/sh)
07-30 03:14:11.182: WARN/su(3595): request rejected (0->0 /system/bin/sh)
07-30 03:14:11.202: WARN/su(3596): request rejected (0->0 /system/bin/sh)
07-30 03:14:11.242: DEBUG/su(3597): 10047 com.bba.stormdroid executing …
Run Code Online (Sandbox Code Playgroud)

java shell android exec su

17
推荐指数
1
解决办法
3万
查看次数

Gatling - 通过JSON数组循环

我有一段代码需要循环通过一个从REST服务的响应中获得的JSON数组.(这里有完整的要点.)

.exec(http("Request_1")
  .post("/endPoint")
  .headers(headers_1)
  .body(StringBody("""REQUEST_BODY""")).asJSON
  .check(jsonPath("$.result").is("SUCCESS"))
  .check(jsonPath("$.data[*]").findAll.saveAs("pList")))
.exec(session => {
  println(session)
  session
})
.foreach("${pList}", "player"){
 exec(session => {
    val playerId = JsonPath.query("$.playerId", "${player}")
    session.set("playerId", playerId)
  })
 .exec(http("Request_1")
    .post("/endPoint")
    .headers(headers_1)
    .body(StringBody("""{"playerId":"${playerId}"}""")).asJSON
    .check(jsonPath("$.result").is("SUCCESS")))

}
Run Code Online (Sandbox Code Playgroud)

第一个请求的响应格式是

{
  "result": "SUCCESS",
  "data": [
    {
      "playerId": 2
    },
    {
      "playerId": 3
    },
    {
      "playerId": 4
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

playerId在会话中显示为

pList -> Vector({playerId=2, score=200}, {playerId=3, score=200}
Run Code Online (Sandbox Code Playgroud)

我在第二次请求中看到了身体

{"playerId":"Right(empty iterator)}
Run Code Online (Sandbox Code Playgroud)

预计:3个身体要求

 {"playerId":1}
 {"playerId":2}
 {"playerId":3}
Run Code Online (Sandbox Code Playgroud)

如果我只保存playerIds,我可以成功遍历结果数组:

.check(jsonPath("$.data[*].playerId").findAll.saveAs("pList")))
Run Code Online (Sandbox Code Playgroud)

json scala jsonpath gatling

10
推荐指数
1
解决办法
2万
查看次数

哪些Java类可以获取并转换系统属性,为什么?

设置的任何系统属性-Dkey=value都可以使用String检索System.getProperty("key").但您也可以获得某些特定类型的系统属性,例如:

Boolean.getBoolean("key"); //Returns true if value==true
Integer.getInteger("key"); //Returns value if exists & is number, else null
Long.getLong("key"); //Ditto as for Integer
Run Code Online (Sandbox Code Playgroud)

有没有其他类的static getSomeClass(String systemPropertyKey)方法?为什么不Byte,FloatDouble拥有它们,但其他原始包装器(或可能是什么原因)?

java system-properties

5
推荐指数
1
解决办法
962
查看次数

正则表达式 - 匹配不包含指定字符串文字的子字符串

使用正则表达式,\*\*([^\*]*)\*\*我可以匹配内部**的多组文本,例如:

this **is** a **test**

回归is&test.

给定字符串that's **right * a test**,如何调整表达式返回right * a test?如何让我的表达式排除两个*而不是一个?

http://regex101.com/r/aD3pC2

regex

3
推荐指数
1
解决办法
153
查看次数

Lvalue需要错误

visual studio不报告此程序的任何错误,而turbo c/c ++表示'函数main中需要左值'

int main()
{
  int a=10,b; 
  a>=5?b=100:b=200;
  printf("%d",b);
  return 0;

}
Run Code Online (Sandbox Code Playgroud)

避免错误:a> = 5?b = 100:(b = 200);

为什么会这样?说明.

c ternary-operator lvalue

1
推荐指数
1
解决办法
1393
查看次数

如何在for循环中捕获计数器的特定值

如何在for循环中捕获计数器的特定值,为此我获得最大计算值...例如:

import com.imonPhysics.projectile2;

public class motion2{

public static void main(String[] args){

    double range=0,v=35,maxrange=0,angle=0;
    int x=0;
    projectile2 p1=new projectile2();
    System.out.println("the given velocity is:  20  m/s \n" );
    System.out.println("The value of g is: 9.8 m/s^2\n\n" );

    for(int j=0;j<=90;j+=5){
      x=j;
      range=p1.calculate(v,j);
      System.out.println("For the angle :" + j+" the range is: " + range);
      if(range > maxrange)maxrange=range;

    }    

    System.out.println(" the maximum range is :"+ maxrange);
    System.out.println(" the angle at which the range is max is :   " + angle);


}

}
Run Code Online (Sandbox Code Playgroud)

如何捕捉最大范围的角度.

java

0
推荐指数
1
解决办法
50
查看次数

使用Python中的正则表达式修改文件内容

我一直在尝试使用Python脚本从以下行中删除编号.

jokes.txt:

  1. 很难向双关语者解释双关语,因为他们总是从字面上理解事物.

  2. 我曾经认为大脑是最重要的器官.然后我想,看看有什么告诉我的.

当我运行这个Python脚本时:

import re
with open('jokes.txt', 'r+') as original_file:
    modfile = original_file.read()
    modfile = re.sub("\d+\. ", "", modfile)
    original_file.write(modfile)
Run Code Online (Sandbox Code Playgroud)

数字仍然存在,它会像这样附加:

  1. 很难向双关语者解释双关语,因为他们总是从字面上理解事物.

  2. 我曾经认为大脑是最重要的器官.然后我想,看看有什么告诉我的.很难向双关语者解释双关语,因为他们总是从字面上理解事物.਍ഀ਍ഀ2.我曾经认为大脑是最重要的器官.然后我想,看看有什么告诉我的.

我想正则表达式会re.sub("\d+\. ", "", modfile)找到所有数字,0-9并用空字符串替换它.

作为一个新手,我不知道我搞砸了哪里.我想知道为什么会发生这种情况以及如何解决这个问题.

python regex

0
推荐指数
1
解决办法
68
查看次数

标签 统计

java ×3

regex ×2

android ×1

c ×1

exec ×1

gatling ×1

json ×1

jsonpath ×1

lvalue ×1

python ×1

scala ×1

shell ×1

su ×1

system-properties ×1

ternary-operator ×1