使用performTaskWithPathArgumentsTimeout函数可以启动哪些进程?
我使用 UIAutomation 来自动化 iPad 应用程序。我尝试过使用 (object) PerformTaskWithPathArgumentsTimeout(path, args, timeout) 从我的脚本运行 Safari.app:
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("/Applications/Safari.app", ["http://www.google.com"], 30);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
我得到以下结果: 退出代码:5 标准输出: stderr:
我也尝试启动 echo:
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("/bin/echo", ["Hello
World"], 5);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
结果: 退出代码:0 标准输出:你好世界 stderr:
所以,看起来 PerformTaskWithPathArgumentsTimeout 仅适用于特定应用程序。
您能帮我回答以下问题吗: 1. exitCode = 5是什么意思? 2. 使用performTaskWithPathArgumentsTimeout函数可以启动哪些进程?
I use UIAutomation to automate an iPad application. I have tried to use
(object) performTaskWithPathArgumentsTimeout(path, args, timeout) to run Safari.app from my script:
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("/Applications/Safari.app", ["http://www.google.com"], 30);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
I got the following results:
exitCode: 5
stdout:
stderr:
I’ve also tried to launch echo:
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("/bin/echo", ["Hello
World"], 5);
UIALogger.logDebug("exitCode: " + result.exitCode);
UIALogger.logDebug("stdout: " + result.stdout);
UIALogger.logDebug("stderr: " + result.stderr);
Results:
exitCode: 0
stdout: Hello World
stderr:
So, looks like performTaskWithPathArgumentsTimeout works for specific applications only.
Could you please help me to answer the following questions:
1. What does exitCode = 5 mean?
2. Which processes can be launched using performTaskWithPathArgumentsTimeout function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 退出代码 5 最有可能是 EIO,如:输入/输出错误中所定义。您正在尝试执行“/Applications/Safari.app”,对于启动任务来说,它是一个目录而不是二进制文件。
2)您可以使用 NSTask 可以启动的 PerformTaskWithPathArgumentsTimeout() 来启动任何应用程序。只要它是有效的可执行文件,它就应该可以工作。
但对于您的具体示例,Safari 不会接受在命令行上传递的参数(例如作为要访问的 URL)。您需要使用
open /Applications/Safari.app "http://www.google.com"
来代替:1) Exit code 5 is most likely EIO, as defined in : Input/Output error. You're attempting to execute "/Applications/Safari.app", which to the launching task is a directory and not a binary.
2) You can launch any application with performTaskWithPathArgumentsTimeout() that NSTask can launch. As long as it's a valid executable, it should work.
For your specific example though, Safari won't accept an argument passed on the command line like that as a URL to visit. You need to use
open /Applications/Safari.app "http://www.google.com"
instead: