12 Jul 2004 17:10
Re: [groovy-dev] groovy -e 'print "hello\n"'
Thanks Joe. I remember Yuri submitting a similar patch that fell through the cracks. Any chance you could supply it again using the +/- style of patch please? http://groovy.codehaus.org/Contributing Incidentally supporting -p -i -e would be cool On 8 Jul 2004, at 16:47, Joe Batt wrote: > I'm new to groovy, so this may have already been discussed and disposed > of before, but here is a patch to allow groovy to be used like awk. > > For example > --- > ps auxwww| groovy -e 'System.in.eachLine { print > it.split("\\s+")[10]+"\n" }' > --- > > There may be a way to avoid the file all together, but I didn't dig > that > deep. > > Joe > > fred:/home/battjt/groovy/groovy-core# cvs diff > src/main/groovy/lang/GroovyShell.java > Index: src/main/groovy/lang/GroovyShell.java > =================================================================== > RCS file: > /home/projects/groovy/scm/groovy/groovy-core/src/main/groovy/lang/ > GroovyShell.java,v > retrieving revision 1.28 > diff -r1.28 GroovyShell.java > 49a50 >> import java.io.FileOutputStream; > 83c84 > < System.out.println("Usage: Groovy groovyScript > [arguments]"); > --- >> System.out.println("Usage: Groovy (groovyScriptFile|-e > groovyScript) [arguments]"); > 86c87,115 > < String scriptName = args[0]; > --- >> int base; >> File file = null; >> if ("-e".equals(args[0])) { >> base = 2; >> FileOutputStream out = null; >> try { >> file = File.createTempFile("groovy", ".groovy"); >> file.deleteOnExit(); >> out = new FileOutputStream(file); >> out.write(args[1].getBytes()); >> } >> catch (IOException e) { >> System.err.println("Unable to process script: " + e); >> e.printStackTrace(); >> } >> finally { >> if (out != null) { >> try { >> out.close(); >> } >> catch (IOException e) { >> // nothing we can do >> } >> } >> } >> } else { >> base = 1; >> file = new File(args[0]); >> } > 88,89c117,118 > < if (length > 1) { > < System.arraycopy(args, 1, newArgs, 0, length - 1); > --- >> if (length > base) { >> System.arraycopy(args, base, newArgs, 0, length - base); > 94c123 > < groovy.run(new File(scriptName), newArgs); > --- >> groovy.run(file, newArgs); > > > James ------- http://radio.weblogs.com/0112098/
RSS Feed