Open-source Languages & Tools for z/OS

 View Only
  • 1.  Request for help (slightly OT, sorry)

    Posted 01-11-2021 05:41
    Hi all,
    sorry if I'm asking something that is not directly related to Rocket Software, but I figured this forum could be my best chance to get an answer, as Google let me down this time 🙁
    I am trying to check for the existence of a directory and create it if it doesn't exist. I'd like to do it in just one command, so I coded this:

    cmd = "test | -e '"||ussLibSvil||"/"||_path||"' && mkdir -p "||ussLibSvil||"/"||_path
    ussrc = bpxwunix(cmd,,stdout.,stderr.,,0)

    The command contained in the cmd variable works correctly if I enter it directly at the shell pormpt.
    However, when run from Rexx code I get this error (the output is mangled by my error trap routine):

    Command: test ! -e '/u/sigdc/sigdc.hna.gitdev/source' && mkdir -p /u/sigdc/sigdc.hna.gitdev/source
    Error: cannot continue (RC = 127)
    Error Detail:
    CMD: FSUM7351 not found
    ***

    I think that the problem lies in the concatenation of commands with "&&", but I can't find a way to fix it. Maybe I need to escape those ampersands somehow? 
    I tried with four ampersands, tried substituting "&" with "\&" but nothing works. Or am I completely off-track?
    Is there anybody that can help me?
    Thank you in advance
    Cris


    ------------------------------
    Cristiano Guadagnino
    Creval
    ------------------------------


  • 2.  RE: Request for help (slightly OT, sorry)

    ROCKETEER
    Posted 01-11-2021 06:06
    Hello Cristiano,

    The following Rexx works fine for me, both within USS and under TSO/ISPF.

    /* Rexx */
    mydir="/my/test/path"
    cmd = "test ! -e '"||mydir||"' && mkdir -p "||mydir
    ussrc = bpxwunix(cmd,,stdout.,stderr.,,0)
    Say cmd
    Say "RC="ussrc

    It does create the directory if it doesn't exist, and bpxwunix returns RC=0.

    I've noticed that in your rexx, there's a pipe "|" between 'test' and '-e' in the script body; however, it's printed as an exclamation mark in the output. Not sure how you were entering it; if /bin/sh truly preceives it as a pipe, this could explain the error (sh executes 'test' and then tries to pipe its output to the next command, which is '-e' and which can't be found anywhere in PATH). In my case, I was typing an exclamation mark and it's displayed correctly in the script body; also, I was typing vertical bars around the 'mydir' variable (even though they are not really needed).

    Regards,
    Vladimir


    ------------------------------
    Vladimir Ein
    Rocket Software
    ------------------------------



  • 3.  RE: Request for help (slightly OT, sorry)

    Posted 01-11-2021 06:25

    Thank you @Vladimir Ein for your reply and for testing my code.
    You're right about the pipe: the point is that I'm developing with Sublime Text editor on my PC and then saving to the mainframe via FTP. During the save, some chars are converted. Pipes are converted to exclamation marks (which, on the mainframe, are used for string concatenation, too). I simply forgot to change the chars when copying/pasting to the forum.
    However your test means the problem lies somewhere else, so I'll be looking harder to find the culprit.
    Thank you!!
    Cris



    ------------------------------
    Cristiano Guadagnino
    Creval
    ------------------------------



  • 4.  RE: Request for help (slightly OT, sorry)

    Posted 01-11-2021 07:25
    Edited by Cristiano Guadagnino 01-11-2021 07:24

    After some more testing I think I've found the problem.
    But first of all: running your code @Vladimir Ein I still get the error.
    So I tried a few tests again, directly from the shell​ through an SSH connection, without being able to identify the problem: every command I tried worked well.

    Finally I tried running the command by logging into the unix shell from the 3270 emulator (i.e. with TSO OMVS) and, at last, the error appeared:

    SIGDC@BVLSYSB (~)$ test ! -e "/u/sigdc/pippo"; echo $?
    -bash: -e: command not found
    127

    The error does NOT occur if I do not use the negation in the test (i.e. if I omit the exclamation mark).
    Any ideas?

    Thank you in advance
    Cris



    ------------------------------
    Cristiano Guadagnino
    Creval
    ------------------------------



  • 5.  RE: Request for help (slightly OT, sorry)

    Posted 01-11-2021 07:31
    Just found the solution, if anybody is interested: I have to use the "]" character instead of the exclamation mark:

    SIGDC@BVLSYSB (~)$ test ] -e "/u/sigdc/pippo"; echo $?
    0

    Weird.

    Cris

    ------------------------------
    Cristiano Guadagnino
    Creval
    ------------------------------



  • 6.  RE: Request for help (slightly OT, sorry)

    ROCKETEER
    Posted 01-11-2021 11:32
    Looks like your terminal (and FTP, too) is configured to use the code page 500 (EBCDIC International), whereas the default code page in USS is EBCDIC 1047. In IBM-1047, the exclamation mark is represented by the byte value x'5A'. In code page 500, however, the same 5A byte represents the right square bracket ']'. That's why 'test ] -e' worked where one would expect to see 'test ! -e'.

    You can probably re-configure your FTP to use IBM-1047. Alternatively, upload your script files in binary mode and tag them with whatever encoding you're using in Sublime Text (most probably ISO8859-1):

    chtag -tc ISO8859-1 myscript.rexx

    One more option would be to convert the script to IBM-1047 right there on your PC (if Sublime supports such an encoding), and then upload it to mainframe without tagging (in binary mode so that it doesn't get converted).

    ------------------------------
    Vladimir Ein
    Rocket Software
    ------------------------------