简体   繁体   English

使用Process exec在Mac中无法执行“ adb shell date> date.txt”命令执行

[英]“adb shell date > date.txt” command execution not working in Mac using Process exec

I have an automation script written in java. 我有一个用Java编写的自动化脚本。 Here is the code sample. 这是代码示例。

 String command = "adb shell date > date.txt";
 Process process = Runtime.getRuntime().exec(command);

When executing the code in windows its working fine but when I am running it in mac its not working properly. 在Windows中执行代码时,其工作正常,但在Mac中运行时,其工作不正常。 Later I found that, in windows this command execution is creating file in my local PC project directory. 后来我发现,在Windows中,此命令执行是在本地PC项目目录中创建文件。 But in case of Mac its failed when trying to create the file in device directory and error showing. 但是在Mac的情况下,尝试在设备目录中创建文件时失败,并显示错误。 While from Mac terminal its working fine. 虽然从Mac终端运行正常。

My question is why is not working in my mac machine and why file is not creating in my local PC? 我的问题是为什么不能在我的mac机上工作,为什么不能在本地PC上创建文件?

The Java Runtime environment doesn't necessarily pick up the same environment variables, command path, and aliases that are at work when you use a macOS Terminal. Java Runtime环境不一定需要使用macOS Terminal时使用的相同环境变量,命令路径和别名。

You might try entering which adb into the Terminal and see what path you get back, if any. 您可以尝试在终端中输入which adb ,然后查看返回的路径(如果有)。 If you do get a definite path, try executing that full path, not just adb , from Java. 如果确实得到了确定的路径,请尝试从Java执行该完整路径,而不仅仅是adb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 adb shell 日期返回值转换为 Java 中的日期对象 - Converting adb shell date returned value to Date Object in Java 命令的java run.exec和shell执行之间有什么区别吗? - Is there any difference between java run.exec of a command and shell execution? Runtime.getRuntime()。exec(command)创建的进程在执行过程中处于休眠状态 - Process Created By Runtime.getRuntime().exec(command) is sleeping in middle of execution Android:adb shell,找不到命令 adb - Android : adb shell, no command adb found 使用Apache Exec在命令执行期间接收反馈 - Receive feedback during a command execution using Apache Exec 使用Java进程exec使用tee命令将telnet输出管道到日志文件 - pipe telnet output to logfile with tee command using Java process exec 使用onClick执行多外壳命令 - Exec multiple shell command with onClick 如何使用ProcessBuilder执行shell重定向(command> output.txt)? - How to perform a shell redirection (command > output.txt) using ProcessBuilder? 无法在 adb shell 中使用 su 命令 - Can't use su command in adb shell Android:无法使用bufferedReader读取文件,而在adb shell中运行的cat命令运行正常 - Android: unable to read a file using bufferedReader whereas cat command run in adb shell works fine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM