Blog Archives

Not Command Revisited

The reason for https://rvdheij.wordpress.com/2011/11/03/fun-with-while-in-specs/ was that I wanted to write something like the “-p” option on the Linux “mkdir” command. This option ensures that “mkdir” creates any intermediate directories needed to produce the full path. Unfortunately CMS lacks this for SFS, so time I wrote my MKDIR-P EXEC to do it.

The parsing of the path into sub-paths is done as in the referenced post. That provides me with a list of directories to check. When the directory does not yet exist, I need to create it. This is a good opportunity to use my favorite not command again. Normally the return code comes out of the secondary output of command. With not you reverse the streams, so return code is out of the primary and command output is on the secondary. This is handy if you don’t want the output of the command.

From the records with directory sub-paths, the fanout gets two copies. The first copy goes through a predsel stage that takes its secondary input (later) to decide whether to write the input record to the primary output (which leads to the command stage) or to secondary output (not connected, so ignored).


   '| o: fanout',           /* The sub-paths generated */
   '| p: predsel',                                       
   '| spec ,CREATE DIR, 1 w1 nw',     /* Build command */
   '| command',             /* .. and execute it       */
   '| cons',                

The other copy of the directory sub-path is used to construct a QUERY DIRATTR command. The not command just retains the return code, and if it is “28” (not there) we use that record to trigger the predsel stage to pass the record to the primary output.

                              
   '\ o:',                                               
   '| spec ,QUERY DIRATTR, 1 w1 nw ',  /* Query to see */
   '| c: not command',      /* if directory is there   */
   '| strfind ,28,',        /* Use 'Not found' to tick */
   '| p:'                   /* one in predsel          */

Depending on the complexity of the pipeline, you may need to wrap this in the privwu stage to have the command run in a private workunit (more about that in a future post).

Design a site like this with WordPress.com
Get started