• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. How to get unix command output in skill

Stats

  • Locked Locked
  • Replies 7
  • Subscribers 144
  • Views 18897
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to get unix command output in skill

wenckey
wenckey over 6 years ago

I want to get some output like "which" for a script's real path in skill script.

My code:

scriptName = "abc.pl"

cid = ipcBeginProcess(strcat("which " scriptName))

realScript = ipcReadProcess(cid)

it can be done in CIW window step by step, but when I put it in a skill file, it will not return the script path.



  • Cancel
  • skillUser
    skillUser over 6 years ago

    Hi,

    Try an ipcWaitForProcess(cid) before the Read.

    Best regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • wenckey
    wenckey over 6 years ago in reply to skillUser

    Thanks for quick response.

    I tried but not working...

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • skillUser
    skillUser over 6 years ago in reply to wenckey

    Really? It should work. The only alternative I might suggest is to try an asynchronous approach by setting up a data handler to receive the result from the IPC process.

    Best regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • wenckey
    wenckey over 6 years ago in reply to skillUser

    See what I did.

    In my tt.il:

    procedure(unixReturn()
    let((cid scriptPath)
    cid = ipcBeginProcess("which cp")
    printf("cid is %s\n" cid)
    ipcWaitForProcess(cid)
    scriptPath = ipcReadProcess(cid)
    printf("S path is %s\n" scriptPath )
    );let
    );prog

    And I run in CIW:

    1) Load the script and run the function, see the print result

    \i load("~/tt.il")
    \o function unixReturn redefined
    \t t
    \i unixReturn()
    \o cid is ipc:61
    \o S path is
    \t t

    2) Type in line by line with the tt.il into the CIW, now I can get the result:


    \i cid = ipcBeginProcess("which cp")
    \t ipc:62
    \i ipcWaitForProcess(cid)
    \t nil
    \i scriptPath = ipcReadProcess(cid)
    \t "/usr/bin/cp\n"
    \i printf("S path is %s\n" scriptPath )
    \o S path is /usr/bin/cp
    \o
    \t t

    Anyone can help on this??

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • tweeksii
    tweeksii over 6 years ago in reply to wenckey

    Ah yes, I encountered this same situation myself, once upon a time...  Slight smile

    It was a fun little puzzle to solve, but if you want to skip to the end of the mystery novel, here is the solution:

    <SPOILERS>

    Replace ipcWaitForProcess(cid) with ipcWait(cid).

    </SPOILERS>

    The reason it's not working from a script is because ipcWaitForProcess() only waits for the process to start up, so you're calling ipcReadProcess() before the process has actually had a chance to produce any output yet.  (Which is why it works from the CIW: in the time it takes you to type ipcReadProcess(cid), the process has finished.)  So in a script, if you want to guarantee that the process has done its thing and printed output for SKILL to read, you need to wait for it to finish, which is what ipcWait() does.  (Yes, I know they're not very good names.)

    If you really want to use ipcWaitForProcess(), then you need to use a while() loop to keep reading and accumulating output text while ipcIsActiveProcess(cid).  

    Note you can also pass a 2nd argument to ipcReadFromProcess(o_childId [x_timeOut]) which tells it to wait x seconds for the process to print something before giving up.

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • tweeksii
    tweeksii over 6 years ago

    wenckey said:

    I want to get some output like "which" for a script's real path in skill script.

    I should also mention that SKILL has various `which'-like commands that can be used without having to resort to ipcBeginProcess(strcat("which " scriptName)).  E.g.,

    simplifyFilename(
    t_name
    [ g_dontResolveLinks ]
    )
    => t_result

    Expands the name of a file to its full path.

    simplifyFilenameUnique(
    t_path
    )
    => t_fullPath / error message

    Returns the full path for the given t_path without links and
    a trailing slash / at the end of the result string. The function
    returns an error if the given t_path is incorrect.

    SKILL novices often reach for ipc* functions to perform simple tasks for which there are already builtin functions (e.g. ipcBeginProcess("whoami") instead of getLogin()).

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • wenckey
    wenckey over 6 years ago in reply to tweeksii

    Really helpful!

    Thanks a lot~

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information