[英]“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.