Gradle不会运行我想要的shell命令行

问题描述 投票:0回答:1

[我已经做了很多Android开发,从来不需要很好地了解gradle。

理想情况下,我会在设置virtualenv之后运行python脚本,但是对于这个问题,我对MWE感到满意。

task rem(type: Exec)  {
    doLast {
        exec {
            workingDir '.'
            commandLine 'dir'
        }
    }
}

结果:

> Task :app:rem FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:rem'.
> execCommand == null!

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
1 actionable task: 1 executed

比方说,在炮击之前,我先回到声明任务的方式:

task rem  {

没有(type: Exec),我得到:

> A problem occurred starting process 'command 'dir''

我以前去过的地方

> execCommand == null!

我只有以下commandLine可用:

task rem(type: Exec)  {
    commandLine 'python', '--version'
}

commandLine 'dir'替换正文失败并

...
> A problem occurred starting process 'command 'dir''
...
windows gradle
1个回答
0
投票

最终偶然发现https://stackoverflow.com/a/37871837/866333来运行Windows脚本并更容易地找到了https://stackoverflow.com/a/50394682/866333链接。

task rem(type: Exec)  {
    commandLine 'cmd', '/c', "cd && virtualenv --python=\"C:\Program Files\Python38\python.exe\" C:\Users\XXX\AndroidStudioProjects\YYY\virtualenvs\ZZZ"
}

上面的代码片段取得了很好的成功(使用双引号,因此我可以从较早的计算中替换XXX YYY ZZZ。这虽然不漂亮,但是python脚本可以。)>

希望这将为我省下更多的新手时间。

注意cd开始(标称)链。我不在我期望的目录中。

© www.soinside.com 2019 - 2024. All rights reserved.