简体   繁体   English

无法运行程序“ osascript”:error = 2,没有这样的文件或目录

[英]Cannot run program “osascript”: error=2, No such file or directory

I am trying to run the following piece of applescript in a selenium test hosted on a remote grid. 我正在尝试在远程网格上托管的硒测试中运行以下小程序。

protected void enableTouchIDLogin(){
   Runtime runtime = Runtime.getRuntime();
   String appleScriptCommand =   "tell application \"System Events\" to tell process \"Simulator\"\n" +
                   "click menu item \"Touch ID Enrolled\" of menu 1 of menu bar item \"Hardware\" of menu bar 1\n"+
                   "end tell";


   String[] args = { "osascript", "-e", appleScriptCommand};
   try
   {
     Process process = runtime.exec(args);
   }
   catch (Exception e)
   {
     e.printStackTrace();
   }
}

When I run the test locally it works fine. 当我在本地运行测试时,它工作正常。 But on the remote grid I get 但是在远程网格上我得到了

java.io.IOException: Cannot run program "osascript": error=2, No such file or directory at java.lang.ProcessBuilder.start(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source)

I'm not sure why this is the case. 我不确定为什么会这样。 On the remote grid 'which osascript' returns ' /usr/bin/osascript.' 在远程网格上,“哪个osascript”返回“ / usr / bin / osascript”。 which is the same location for my osascript when running locally. 在本地运行时,这是我的osascript的相同位置。

Given that the path both locally and on the remote grid is the same i'm not sure why the -e flag doesnt work. 鉴于本地和远程网格上的路径都是相同的,我不确定-e标志为什么不起作用。 I'm not sure what my appleScriptCommand should look like... 我不确定appleScriptCommand应该是什么样子...

EDIT 编辑

As per one of the replies here i tried the following which doesn't throw an error but also doesn't perform the functionality locally or remotely. 根据这里的答复之一,我尝试了以下操作,该操作不会引发错误,但是不会在本地或远程执行功能。

  protected void enableTouchIDLogin(){



   try
   {
       Runtime runtime = Runtime.getRuntime();
       String appleScriptCommand =   "tell application \"System Events\" to tell process \"Simulator\"\n" +
                       "click menu item \"Touch ID Enrolled\" of menu 1 of menu bar item \"Hardware\" of menu bar 1\n"+
                       "end tell";

       File executor = File.createTempFile("exec", ".sh");
       PrintWriter writer = new PrintWriter(executor, "UTF-8");
       writer.println("#!/bin/bash");
       writer.println();
       writer.println(String.format("osascript -e \"do shell script \\\"%s\\\" with administrator privileges\"",
                       appleScriptCommand));
       writer.close();
       executor.setExecutable(true);

       Process process = runtime.exec(String.format("%s",
                       executor.getPath()));
   }
   catch (Exception e)
   {
       e.printStackTrace();
   }

  }   

This works good for me 这对我有用
UPDATE5: UPDATE5:

String script = "tell application \\\"System Events\\\" to tell process \\\"Simulator\\\"\n" +
                   "click menu item \\\"Touch ID Enrolled\\\" of menu 1 of menu bar item \\\"Hardware\\\" of menu bar 1\n"+
                   "end tell";
File executor = File.createTempFile("exec", ".sh");
PrintWriter writer = new PrintWriter(executor, "UTF-8");
writer.println("#!/bin/bash");
writer.println();
writer.println(String.format("osascript -e \"%s\" with administrator privileges",
        script);
writer.close();
executor.setExecutable(true);

Runtime.getRuntime().exec(String.format("%s", 
        executor.getPath()));

暂无
暂无

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

相关问题 无法运行程序“ docker”,错误= 2,无此文件或目录 - Cannot run program “docker” error=2, No such file or directory 无法运行程序“...”错误= 2,没有这样的文件或目录(java) - Cannot run program “…” error=2, No such file or directory (java) 无法运行程序“mvn”错误=2,没有这样的文件或目录 - Cannot run program "mvn" error=2, No such file or directory 詹金斯:无法运行程序“docker”:错误=2,没有那个文件或目录 - Jenkins : Cannot run program “docker”: error=2, No such file or directory im4java中出现错误,无法运行程序“转换”:错误= 2,没有此类文件或目录 - Error in im4java, Cannot run program “convert”: error=2, No such file or directory 无法运行程序“wkhtmltopdf”:错误=2,没有这样的文件或目录 - 从 Java 获取此错误 - Cannot run program "wkhtmltopdf": error=2, No such file or directory - Getting this error from Java ant jar错误:执行失败:java.io.IOException:无法运行程序... $ {aapt}“:error = 2,没有这样的文件或目录 - ant jar error: Execute failed: java.io.IOException: Cannot run program…${aapt}": error=2, No such file or directory spark 2.0-java.io.IOException:无法运行程序“ jupyter”:error = 2,没有这样的文件或目录 - spark 2.0 - java.io.IOException: Cannot run program “jupyter”: error=2, No such file or directory 无法启动测试系统'slim':java.io.IOException:无法运行程序“ java”:error = 2,没有这样的文件或目录 - Unable to start test system 'slim': java.io.IOException: Cannot run program “java”: error=2, No such file or directory java.io.IOException:无法运行程序“usr/bin/ffmpeg”:错误=2,没有那个文件或目录 - java.io.IOException: Cannot run program “usr/bin/ffmpeg ”: error=2, No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM