How to Cancel Command in Grunt Shell

Exit pig shell command safely

I've looked in the pig source code. This is called the secondary_prompt (found in PigScriptParser.jj, a context-free parser grammar file for JavaCC). To my eye it looks like it can't be gotten out of. I tried a lot of combinations of things I saw in that code and nothing worked. Also tried all the exit type words I could think of, to no avail.

When I did Ctrl + D, it exited and displayed:

>> 2013-06-19 12:51:43,632 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1000:
Error during parsing. Lexical error at line 83, column 0. Encountered: <EOF> after : ""

Looking in the Grunt class, at that point, it does:

parser.setInteractive(false);
return parser.parseStopOnError();

This suggests to me that interactivity is over at this point.

running script with exec command from grunt

It means you can have a Pig script pre-written and execute it with exec. Example taken from: http://pig.apache.org/docs/r0.7.0/piglatin_ref2.html#exec

grunt> cat myscript.pig
a = LOAD 'student' AS (name, age, gpa);
b = LIMIT a 3;
DUMP b;

grunt> exec myscript.pig
(alice,20,2.47)
(luke,18,4.00)
(holly,24,3.27)

This is beneficial if you have a set of commands you run on a regular basis. Rather then retyping it each time, you can put it in a script and run exec on it.

Grunt-shell save command output as variable

Found that I can actually do this using a config variable (instead of global) inside the callback. (Note below line also removes the newline).

grunt.config.set('gitCommitNo', stdout.replace('\n', '')); 

Then this can be accessed using:

<%=gitCommitNo%>

How to enter two commands in pig gruntshell without typing enter key?

You can create a pig script file to make it as single execution.

test.pig

A = LOAD '/pig/student.tsv' as (rollno:int, name:chararray, gpa:float); 
DUMP A;

Now run the pig script using below command from pig/bin,

pig -f /path/test.pig


Related Topics



Leave a reply



Submit