Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
Groovy has numerous features for improving Java's external process execution. This issue is about packaging those features up in a more concise way. This supercedes GROOVY-5049 (thanks goes to Uri Moszkowicz for raising many of the issues).
So for this Perl example here:
if (`ls *.ext1` =~ /\S+/) {
...
} elsif (`ls *.ext2` =~ /\S+/) {
...
}
Currently a solution might look like this:
def sb1 = new StringBuffer() def process1 = "ls *.ext1".execute() process1.waitForProcessOutput(sb1, sb1) def sb2 = new StringBuffer() def process2 = "ls *.ext2".execute() process2.waitForProcessOutput(sb2, sb2) if (sb1 =~ /\S+/) { ... else if (sb2 =~ /\S+/) { ... }
The intention would be to provide something like:
if (Process.execute('ls *.ext1') =~ /\S+/) { ... else if (Process.execute('ls *.ext2') =~ /\S+/) { ... }
as a shorter alternative (perhaps even shorter after a static import).
For more complicated scenarios we might have:
Process.execute(command: 'ls *.ext1', timeout: 5000, redirectErrorStream: true, wasKilled: { println 'FAILED!' })
This is combining ideas from GROOVY-4991 and GROOVY-4992.
The intention would be to use Java's ProcessBuilder if needed and see if we can learn anything from org.jruby.util.ShellLauncher which does things like adds 'cmd /c' in front of internal commands on Windows and is are of standard pasth prefixes, e.g. /usr/bin and handles channels for the inputs and outputs if needed.
Issue Links
- relates to
-
GROOVY-4991
Add redirectErrorStream() to Process
-
-
GROOVY-4992
Add WasKilled() to Process
-
- supercedes
-
GROOVY-5049
File.getText() should close the streams
-