菜鸟教程小白 发表于 2022-12-12 20:19:52

ios - 如何消除 performTaskWithPathArgumentsTimeout 的 1 秒延迟


                                            <p><p>我在我的 ios ui 脚本中使用 performTaskWithPathArgumentsTimeout,在执行命令之前似乎引入了隐藏的 1 秒延迟。</p>

<pre><code>var target = UIATarget.localTarget();
var host = target.host();

var start = new Date().getTime();
var result = host.performTaskWithPathArgumentsTimeout(&#34;/bin/echo&#34;, [&#34;Hello World&#34;], 5);
var total = new Date().getTime() - start;

UIALogger.logDebug(&#34;duration: &#34; + total);
</code></pre>

<p>输出:
持续时间:1001</p>

<p>所有命令都一样。从命令行启动时即时,但通过 performTask 启动时会有 1 秒的延迟。</p>

<p>关于如何减少这种延迟的任何想法?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>此延迟与 UI 自动化在内部启动命令的方式有关。从头到尾我们无能为力。</p>

<p>也就是说,如果您有很多命令要按顺序执行,您可以将它们全部放在一个 shell 脚本中并像这样执行它:</p>

<pre><code>host.performTaskWithPathArgumentsTimeout(&#34;/bin/bash&#34;, [&#34;some_shell_script.sh&#34;], 5);
</code></pre>

<p>这将在 bash 中运行给定的 shell 脚本文件,您只需支付 1 秒的进程启动惩罚一次。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何消除 performTaskWithPathArgumentsTimeout 的 1 秒延迟,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/10138407/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/10138407/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何消除 performTaskWithPathArgumentsTimeout 的 1 秒延迟