How to execute a command line process ? (tried with Exec but not worked)

Hi,

Now I’m building Gradle in Cygwin in Windows 7 64bit. In Cygwin, I run the command successfully on a terminal: “gem install compass” I can use maven-exec-plugin to call that command in Maven.

But how should we call in Gradle ?

I have tried with Exec but not done successfully:

task installCompass(type:Exec) {
    commandLine 'gem', 'install', 'compass'
}

Thanks, Phuong.

Hey Phuong, Your snippet works fine on my machine. What error do you get? can you run gradle with “-i” to get more output? Do you have “gem” on your path?

cheers, René

Hi René,

I think “gem” is on path now because I can run that command everywhere in Cygwin’s terminal.

Below is the error when run with --info:

Process 'command 'gem'' finished with exit value -1 (state: FAILED)
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':activation:prepareCss'.
> A problem occurred starting process 'command 'gem''

And with --debug: ( The PATH contains “gem” definitely.)

[DEBUG] [org.gradle.process.internal.DefaultExecHandle] Environment for process 'command 'gem'': {TERM=xterm, USERPROFILE=C:\Users\phuonglu, columes=179, JAVA_HOME=/cygdrive/c/Program Files (x86)/Java/jdk1.6.0_32, COMMONPROGRAMFILES=C:\Program Files (x86)\Common Files, PWD=/cygdrive/d/working/idondemandrepo/core/activation, HOSTNAME=phuonglu-PC, PROCESSOR_REVISION=2502, USERDOMAIN=phuonglu-PC, ALLUSERSPROFILE=C:\ProgramData, tmp=C:\Users\phuonglu\AppData\Local\Temp, SESSIONNAME=Console, HISTSIZE=2000, TMP=C:\cygwin\tmp, LOGONSERVER=\PHUONGLU-PC, =::=::\, M2_HOME=D:\working\maven304, PATH=C:\cygwin\usr\local\bin;C:\cygwin\bin;C:\Program Files (x86)\PC Connectivity Solution;C:\oraclexe\app\oracle\product0.2.0\server\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\ActivIdentity\ActivClient;C:\Program Files (x86)\ActivIdentity\ActivClient;C:\Program Files (x86)\Symantec\VIP Access Client;C:\Program Files\Java\jdk1.6.0_32\bin;D:\working\maven304\bin;D:\working\ant\bin;D:\working\groovy\groovy-2.0.1\bin;C:\Program Files (x86)\Git\bin;C:\oraclexe\app\oracle\product0.2.0\server\BIN;C:\cygwin\lib\lapack, VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\, PROCESSOR_LEVEL=6, WIX=C:\Program Files (x86)\Windows Installer XML v3\, LOCALAPPDATA=C:\Users\phuonglu\AppData\Local, COMPUTERNAME=PHUONGLU-PC, INFOPATH=/usr/local/info:/usr/share/info:/usr/info:, temp=C:\Users\phuonglu\AppData\Local\Temp, USERNAME=phuonglu, lines=44, TZ=Asia/Bangkok, APPDATA=C:\Users\phuonglu\AppData\Roaming, WINDIR=C:\Windows, ProgramData=C:\ProgramData, PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC, windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log, SHLVL=1, ProgramFiles(x86)=C:\Program Files (x86), MANPATH=/usr/local/man:/usr/share/man:/usr/man::/usr/ssl/man, GROOVY_HOME=D:\working\groovy\groovy-2.0.1, TEMP=C:\cygwin\tmp, windows_tracing_flags=3, SVN_EDITOR=vim, HOMEDRIVE=C:, JAVA_OPTS=-Xms128m -Xmx1300m -XX:MaxPermSize=300m -Dsun.security.ssl.allowUnsafeRenegotiation=true, SYSTEMDRIVE=C:, VS90COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\, ProgramW6432=C:\Program Files, PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 37 Stepping 2, GenuineIntel, OLDPWD=/cygdrive/d/working/idondemandrepo/core, SHELL=/bin/bash, PRINTER=HDP5000 Card Printer, MAVEN_OPTS=-Xmx1024M -XX:MaxPermSize=300m, PROCESSOR_ARCHITECTURE=x86, FP_NO_HOST_CHECK=NO, OS=Windows_NT, PROCESSOR_ARCHITEW6432=AMD64, HOMEPATH=\Users\phuonglu, JBOSS_HOME=D:\working\jboss-as-7.1.1.Final, COMSPEC=C:\Windows\system32\cmd.exe, CommonProgramW6432=C:\Program Files\Common Files, USER=phuonglu, ANT_HOME=D:\working\ant, CATALINA_HOME=D:\working\apache-tomcat-6.0.32\, PROGRAMFILES=C:\Program Files (x86), HOME=C:\cygwin\home\phuonglu, HISTCONTROL=ignoreboth, NUMBER_OF_PROCESSORS=4, SYSTEMROOT=C:\Windows, PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\, PUBLIC=C:\Users\Public, CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files, LANG=C.ASCII}
16:48:11.540 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
16:48:11.541 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command 'gem'.
16:48:11.546 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
16:48:11.546 [INFO] [org.gradle.process.internal.DefaultExecHandle] Process 'command 'gem'' finished with exit value -1 (state: FAILED)
16:48:11.547 [DEBUG] [org.gradle.logging.internal.DefaultLoggingConfigurer] Finished configuring with level: DEBUG, configurers: [org.gradle.logging.internal.OutputEventRenderer@888e6c, org.gradle.logging.internal.logback.LogbackLoggingConfigurer@13e58d4, org.gradle.logging.internal.JavaUtilLoggingConfigurer@39e5b5]
16:48:11.547 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':activation:prepareCss'
16:48:11.559 [ERROR] [org.gradle.BuildExceptionReporter]
16:48:11.562 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
16:48:11.562 [ERROR] [org.gradle.BuildExceptionReporter]
16:48:11.562 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
16:48:11.562 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':activation:prepareCss'.
16:48:11.565 [ERROR] [org.gradle.BuildExceptionReporter] > A problem occurred starting process 'command 'gem''
16:48:11.566 [ERROR] [org.gradle.BuildExceptionReporter]
16:48:11.566 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
16:48:11.567 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':activation:prepareCss'.
16:48:11.568 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:68)
16:48:11.569 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
16:48:11.570 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34)
16:48:11.570 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$1.run(CacheLockHandlingTaskExecuter.java:34)
16:48:11.570 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAccess.java:200)
16:48:11.570 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:172)
16:48:11.570 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198)
16:48:11.571 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:137)
16:48:11.571 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
16:48:11.571 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(CacheLockHandlingTaskExecuter.java:32)
16:48:11.571 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)
16:48:11.572 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
16:48:11.572 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
16:48:11.572 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
16:48:11.572 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
16:48:11.573 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
16:48:11.573 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:247)
16:48:11.573 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:192)
16:48:11.573 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:177)
16:48:11.573 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:83)
16:48:11.574 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:36)
16:48:11.574 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
16:48:11.574 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
16:48:11.574 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
16:48:11.574 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
16:48:11.575 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.cache.internal.DefaultCacheAccess$1.create(DefaultCacheAccess.java:111)
16:48:11.575 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:126)
16:48:11.575 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:109)
16:48:11.575 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:129)
16:48:11.575 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
16:48:11.576 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
16:48:11.576 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
16:48:11.576 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
16:48:11.576 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
16:48:11.576 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
16:48:11.576 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
16:48:11.577 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
16:48:11.577 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:155)
16:48:11.578 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
16:48:11.578 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)
16:48:11.578 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)
16:48:11.579 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
16:48:11.582 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)
16:48:11.583 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
16:48:11.583 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)
16:48:11.583 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)
16:48:11.583 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:200)
16:48:11.583 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:173)
16:48:11.583 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
16:48:11.584 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:138)
16:48:11.584 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
16:48:11.584 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
16:48:11.584 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.Main.doAction(Main.java:48)
16:48:11.584 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
16:48:11.584 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.Main.main(Main.java:39)
16:48:11.584 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
16:48:11.585 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
16:48:11.585 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
16:48:11.585 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
16:48:11.585 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
16:48:11.585 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:47)
16:48:11.585 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'gem''
16:48:11.586 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:195)
16:48:11.586 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:325)
16:48:11.586 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:90)
16:48:11.586 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
16:48:11.586 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.io.IOException: Cannot run program "gem" (in directory "D:\working\idondemandrepo\core\activation"): CreateProcess error=2, The system cannot find the file specified
16:48:11.586 [ERROR] [org.gradle.BuildExceptionReporter]
      at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:71)
16:48:11.587 [ERROR] [org.gradle.BuildExceptionReporter]
      ... 1 more
16:48:11.587 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
16:48:11.587 [ERROR] [org.gradle.BuildExceptionReporter]
      ... 2 more

Thanks, Phuong.

Can anybody help me ?

If it works on the command prompt, it might be a compatibility issue with cygwin. From my personal experience, I would recommend to run Gradle from the command prompt rather than from cygwin.

The problem here is that some projects with native components may depend on Cygwin for their Windows builds. I verified this is still an issue. I intend to see if this ( https://github.com/derianto/Gradle-Cygwin-Toolkit-Plugin) helps, but it is old, and I’m a Gradle newbie trying to use Gradle for native projects, which seems to pose a number of obstacles.

Note the above plugin does not seem to help.