0
How to Identify error given by PVCS.
e.g. I am getting one file from PVCS and if that file does not exist on PVCS then error will be given. So how to check that error, because depending on that error I have to write next steps of the code.

I am using PCLI (batch file) related commands. Language used is Python

Any command is there to handle such kind of errors?

Accepted Answer

Tuesday, March 01 2016, 10:47 AM - #Permalink
0
Hello Chinar,

Drewster makes some good points.

If you need to operate on multiple files and performance is a concern, using a PCLI script it preferable because it avoids having to relaunch the PCLI interpreter and it keeps the File Server Client Cache data in tact between command runs (see KB S132411).

PCLI isn't the easiest of scripting languages to work with, but you can typically get the job done.

Within a PCLI script you can capture the exit code of the previous command using #?. As #? gets reset after each command, store it in a variable and test that variable.

Example:
get -vMyLabel /chess/server/server.bat
set RC=$?
if [ $RC != 0 ]
{
echo "The get command failed with RC=$RC"
}

Except for the negative command invocation error values (documented in the PCLI manual) there typically isn't a universal meaning for an exit code, so you'll have to play with the command and see what it returns.

If you have specific needs or examples, please show them so we can discuss those in more detail. For example, often it's better to figure out if a file exists before trying to fetch it, but whether that's an option depends on the specific use case.

Kind regards,

- Richard.
The reply is currently minimized Show
Responses (6)
  • Accepted Answer

    Drewster
    Drewster
    Offline
    Tuesday, March 01 2016, 07:26 AM - #Permalink
    0
    Depending on exactly what you are trying to do (and the process/logic required depending on the various results)
    plus obviously if it is a "one off"/irregular activity or an ongoing repeated activity.......

    You have a few options (pretty well irrespective of language etc).

    At the two extremes:
    1) "Check for the file"............ and based on the result.......
    a) Do lots and lots of processing etc "outside" PVCS (plus possibly some trivial stuff "inside" PVCS)........................

    ......
    2) "Check for the file"............ and based on the result.......
    a) Do lots and lots of processing etc "inside " PVCS (plus possibly some trivial stuff "outside" PVCS)........................

    I the first case it might be "easiest" to just issue a single PVCS GET to a "temp file"............
    then check for the existence of the "temp file"......
    and then do all the (outside PVCS) work/processing required............

    Pros:
    You only need to "learn" a single PVCS PCLI command (and do "everything else" in the language of choice)
    Cons: A "dirty" solution from the PVCS perspective - Issue a GET and then sort it out afterwards.........

    In the second case you might benefit from (more) fully utilizing the PCLI scripting functionality....
    Pros: Once "learnt" the (efficient use of) PCLI functionality could be used in future etc etc
    Cons: You have to "learn" all about PCLI and its options.......... and it might not even be able to do it after all that effort......
    Like
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, March 02 2016, 03:55 AM - #Permalink
    0
    Thank you both. My purpose is solved.

    One more question is about "Get -id"

    Now I have written a script in Python for PCLI command. Where I am telling user to enter his or her USER ID and password.
    Now here is the possibility that incorrect password or may be incorrect user ID ;) is entered then PVCS will not be accessed.
    So how to detect this error?
    Currently i have written the code is working fine if user id and password entered are correct.
    Please reply
    The reply is currently minimized Show
  • Accepted Answer

    Drewster
    Drewster
    Offline
    Wednesday, March 02 2016, 06:08 AM - #Permalink
    0
    I think (I am sure Richard can confirm) that running PCLI with incorrect (login) parameters will generate a NON-ZERO return code (to the O/S)......

    So you need conditional processing (in Python or whatever you are using) to test for that error....
    a) If it finds it - sort it out
    b) Otherwise - Do whatever needs doing..... (which might be nothing if you have fully processed your stuff within your (successful) PCLI invocation.......)

    Something along the lines of:
    /* Bit where you prompt for UserID and password......

    /* Bit where you invoke PCLI with whatever parameters you need....
    PCLI blah blah bad-parameter blah blah
    IF RC = "Failed because of bad parameter" then do (
    print "You entered a bad parameter/userid etc"
    print "Try again you Numpty!"
    goto The bit where you enter your Userid and Password.......)
    else (It didn't fail because of bad parameter)... Do stuff

    Obviously you could EXIT from this logical loop at some point (rather than just repeatedly storming with incorrect UID/PWd)

    (Obviously) depending on your tool your logical thought process etc you might:
    a) Test for "Successful processing" 1st....
    b) and have "FAILURE" as the ELSE condition (as logically you would expect that to be the exception........)
    You could even (in ELSE failure condition) break it down into type of FAILURE
    i) Login failure
    ii) Processing failure
    iii) etc

    So in each invocation:
    a) Test for success (every invocation)........... exit nice and cleanly 99% of the time
    (No overhead of "what to do in event of failure......)

    b) else (if NOT success)...... do further checking.... and process accordingly

    hth
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, March 02 2016, 10:40 AM - #Permalink
    0
    What Drewster said :-)

    The mechanism to detect exit codes is language dependent, but PCLI will set a non-zero exit code on failure. Example:
    D:\>pcli whoami -prD:\proj -idAdmin:admin
    Serena PVCS Version Manager (PCLI) v8.4.6.0 (Build 037) for Windows NT/80x86
    Copyright 1985-2012 Serena Software. All rights reserved.
    Admin

    D:\>echo %ERRORLEVEL%
    0

    D:\>pcli whoami -prD:\proj -idAdmin:WRONG
    Serena PVCS Version Manager (PCLI) v8.4.6.0 (Build 037) for Windows NT/80x86
    Copyright 1985-2012 Serena Software. All rights reserved.
    08:30:42 Mar.02.16 [Error]
    You cannot access this project because your login account, Admin, is invalid. Please try to login again or contact your
    Serena administrator for further assistance.

    D:\>echo %ERRORLEVEL%
    -3

    D:\>
    There is no guarantee that -3 is always a login error, but login errors do set the exit value to -3. Depending on the OS/language used, negative values may be remapped to positive ones. For example, Linux effectively adds 256 to any negative exit code, so -1 = 255, -2 = 254, -3 = 253.

    Hope this helps!

    - Richard.
    • Chinar Umesh Teredesai
      more than a month ago
      Thank you Richard. I am getting same error level. Next task is to extract it in function.

      I will try that otherwise will raise a query once again.

      Thank you once again.
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, March 03 2016, 03:26 AM - #Permalink
    0
    Please have a look at following code written in Python

    fd = open('PVCS.bat', 'w')
    fd.write("@echo off")
    fd.write("\n")
    PCLICommand = "pcli Run -y Get -id"+str(PVCSID)+":"+str(PVCSPassword)+" -pr\\\PVCS\ABC -pp/AB_"+str(ab)+"_xyz"+str(cu)+"/po_folder -z -w ABCDEF_Folder"
    fd.write(PCLICommand)
    fd.write("\n")
    fd.write("@echo %ERRORLEVEL%")

    This code is written in one function and last statement is printing error level on command prompt as expected. But how can I get that value to compare the same like

    if error_Return != 0 :
    print 'axvfdf blah blah'

    Please reply.
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, March 03 2016, 12:01 PM - #Permalink
    0
    Hello Chinar,

    The use of %ERRORLEVEL% in CMD.EXE was merely an example to show how PCLI sets an exit code that the calling environment can query. I do not recommend you echo this from a batch file and try to interpret its value.

    Instead, I would call PCLI directly from Python and use it's native return value querying mechanisms to retrieve PCLI's exit code. That mechanism will depend on how you call PCLI.

    Could be:
    p = subprocess.Popen('pcli...);
    retval = p.wait();

    Could be:
    reval = os.system('pcli...');

    There are likely some additional ways as well in Python, depending on how you call PCLI.

    Note that you can still use a batch-file as an intermediate, should there be other reasons for doing so. Just make the pcli command the last command in the batch file, so its exit code will determine the exit code for the batch file itself as well.

    Kind regards,

    - Richard.
    The reply is currently minimized Show
Your Reply

Recent Tweets