Skip to main content
1-Visitor
December 22, 2016
Solved

MKS command automation Python

  • December 22, 2016
  • 3 replies
  • 7834 views

Hi,

I am trying to automate MKS commands using python. Please help me to capture the error message.

Example:

import subprocess

import time

viewproject_cmd='im issues'
proc = subprocess.Popen(viewproject_cmd,stdout=subprocess.PIPE,shell=True)

(out, err) = proc.communicate()

The above script is throwing me following error,

*** MKS124814: Cannot show view information: MKS124808: This command requires operands: item id

I am unable to capture the above error in any variable. Also I see this error only if I execute the above python script in the cmd.exe

Please help me to handle the above error in python script itself.

    Best answer by dmuniappan

    I have got the answer to my question, The below code returns error message if there is any error on execution of si command

    import subprocess

    viewproject_cmd='im issues'
    process = subprocess.Popen(viewproject_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

    (out, err) = process.communicate()

    print '!!!!ERROR:',err

    3 replies

    12-Amethyst
    December 22, 2016

    I dont know nothing about python but the command line perspective 2 informations may help you.

    1.)

    The error text is output to stderr. To capture it you could do something like

        im issues 2> err.txt

    2.)

    the error code may be visible in the environment variable %errorlevel% after the command has finished

        echo %errorlevel%

    Regards

         Juergen

    1-Visitor
    December 23, 2016

    Thanks Juergen,

    dmuniappan1-VisitorAuthorAnswer
    1-Visitor
    December 23, 2016

    I have got the answer to my question, The below code returns error message if there is any error on execution of si command

    import subprocess

    viewproject_cmd='im issues'
    process = subprocess.Popen(viewproject_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

    (out, err) = process.communicate()

    print '!!!!ERROR:',err

    1-Visitor
    September 8, 2017

    Hi,

    Can you please tell me from where I can get the list of Python APIs for MKS?