SPL File TestShellPipeBasic1.spl

Toolkits > SampleShellPipe 1.1.0 > sample > TestShellPipeBasic1.spl

Content

Operators
  • TestShellPipeBasic1: This sample application executes a variety of scripts with the ShellPipe operator, flowing Streams tuple attributes through the scripts, and storing their STDOUT in files.

Composites

public composite TestShellPipeBasic1

This sample application executes a variety of scripts with the ShellPipe operator, flowing Streams tuple attributes through the scripts, and storing their STDOUT in files.

The scripts copy copies lines of text from STDIN to STDOUT, prefixing them with line numbers and the number of characters on each line. The operator writes lines of text consumed from input tuples to STDIN, and produces output tuples containing lines of text read from STDOUT. This application does not expect the scripts to write anything to STDERR, If something is written to STDERR, it will be discarded.

This application illustrates how to execute Bash and Perl scripts, either stored in files or coded directly in the ShellPipe operator specification. This application also illustrates how to specify explicitly which input and output attributes are used for STDIN and STDOUT, respectively, and how the operator chooses attributes when not specified.

The scripts can be tested independently of Streams by entering these commands at a Linux prompt:

cd .../samples/SampleShellPipe
cat ./data/ozymandias.txt | ./etc/lineCounter1.sh

or

cd .../samples/SampleShellPipe
cat ./data/ozymandias.txt | ./etc/lineCounter1.pl

Parameters

SPL Source Code


 composite TestShellPipeBasic1 {
 
     param
     expression<rstring> $inputFile: dataDirectory() + "/ozymandias.txt";
 
     graph
 
 
     // create a stream of text lines for the ShellPipe operators below to consume
     stream<rstring inputLine> InputStream = FileSource() {
     param
         file: $inputFile;
         format: line; }
     () as DebugInputStream = FileSink(InputStream) { param file: "debug.TestShellPipeBasic1.InputStream.out"; format: txt; hasDelayField: true; flush: 1u; writePunctuations: true; }
 
 
     // execute a Bash script from a file that consumes STDIN, counts lines, and produces STDOUT
     stream<rstring stdoutLine> A_STDOUTStream = ShellPipe(InputStream) {
     param
         command: "./etc/lineCounter1.sh"; }
     () as DebugA_STDOUTStream = FileSink(A_STDOUTStream) { param file: "debug.TestShellPipeBasic1.A_STDOUTStream.out"; format: txt; hasDelayField: true; flush: 1u; writePunctuations: true; }
 
 
     // execute a Bash script from a file that consumes STDIN, counts lines, and produces STDOUT
     stream<rstring stdoutLine> B_STDOUTStream = ShellPipe(InputStream) {
     param
         command: "./etc/lineCounter1.sh";
         stdinAttribute: inputLine;
         stdoutAttribute: "stdoutLine"; }
     () as DebugB_STDOUTStream = FileSink(B_STDOUTStream) { param file: "debug.TestShellPipeBasic1.B_STDOUTStream.out"; format: txt; hasDelayField: true; flush: 1u; writePunctuations: true; }
 
 
     // execute a Perl script from a file that consumes STDIN, counts lines, and produces STDOUT
     stream<rstring stdoutLine> C_STDOUTStream = ShellPipe(InputStream) {
     param
         command: "./etc/lineCounter1.pl"; }
     () as DebugC_STDOUTStream = FileSink(C_STDOUTStream) { param file: "debug.TestShellPipeBasic1.C_STDOUTStream.out"; format: txt; hasDelayField: true; flush: 1u; writePunctuations: true; }
 
 
     // execute an inline Bash script that consumes STDIN, counts lines, and produces STDOUT
     stream<rstring stdoutLine> D_STDOUTStream = ShellPipe(InputStream) {
     param
         command: "bash -c \"count=0; while read line ; do (( count += 1 )) ; echo \\$count \\${#line} \\$line ; done\"";
         stdinAttribute: inputLine;
         stdoutAttribute: "stdoutLine"; }
     () as DebugD_STDOUTStream = FileSink(D_STDOUTStream) { param file: "debug.TestShellPipeBasic1.D_STDOUTStream.out"; format: txt; hasDelayField: true; flush: 1u; writePunctuations: true; }
 
 
     // execute an inline Perl script that consumes STDIN, counts lines, and produces STDOUT
     stream<rstring stdoutLine> E_STDOUTStream = ShellPipe(InputStream) {
     param
         command: "perl -n -e \"print ++\\$count . ' ' . length(\\$_) . ' ' . \\$_\"";
         stdinAttribute: inputLine;
         stdoutAttribute: "stdoutLine"; }
     () as DebugE_STDOUTStream = FileSink(E_STDOUTStream) { param file: "debug.TestShellPipeBasic1.E_STDOUTStream.out"; format: txt; hasDelayField: true; flush: 1u; writePunctuations: true; }
 
 
     // execute an inline Perl script that consumes STDIN, copies lines, and produces STDOUT
     stream<rstring stdoutLine> F_STDOUTStream as Out = ShellPipe(InputStream) {
     param
         command: "perl -n -e \"print \\$_\"";
     output Out:
         stdoutLine = (rstring)lineCounters()[1] + " " + (rstring)length(stdoutLine()) + " " + stdoutLine(); }
     () as DebugF_STDOUTStream = FileSink(F_STDOUTStream) { param file: "debug.TestShellPipeBasic1.F_STDOUTStream.out"; format: txt; hasDelayField: true; flush: 1u; writePunctuations: true; }
 
 }