Running Calibre in background by skill

Discussion in 'Cadence' started by bedoune, May 7, 2008.

  1. bedoune

    bedoune Guest

    hi,

    I writing a skill that runs Calibre automatically.
    I fill my options files automatically and then i run Calibre by
    command:
    csh(Com)
    where Com = strcat("calibre" ...)


    It works fine but i'm facing a problem. During the execution of the
    command, Cadence is frozen and i have to wait ... i can't work during
    this time.

    So i tried to add "&" in my command :

    Com = strcat("calibre" ... "&")
    csh(Com)

    In this case, the skill program is continuing but behavior of my skill
    program is not as expected !


    So i found an old topic about asynchronous code:


    procedure(MYdataHandler(ipcId data)
    printf("%s" data)
    )

    procedure(MYexitHandler(ipcId exitStatus)
    printf("Process %L exited with status %d\n" ipcId exitStatus)
    )

    id=ipcBeginProcess("ls" "" 'MYdataHandler 'MYdataHandler
    'MYexitHandler)


    But i don't understand how it works and how to modify it to fit my
    code.

    could someone help me please ?

    Thanks and regards,

    b.
     
    bedoune, May 7, 2008
    #1
  2. bedoune

    jayl-news Guest

    bedoune,

    Check out the IPC reference manual, doc/skipcref/skipcref.pdf, it's
    not bad and has trivial examples like you want.

    To do the equivalent of your simple "csh(Com)", you want to
    use ipcBatchProcess(), not ipcBeginProcess().

    Using your same command string Com, you would do something
    like:

    ipcBatchProcess(Com "" "./calibre.log")

    There's no error checking there, or results notification, but you
    weren't doing any before, either!

    -Jay-
     
    jayl-news, May 7, 2008
    #2
  3. bedoune

    Riad KACED Guest

    Hi There !

    If I well understood your description, you don't seem to be interested
    in communicating with your child process (calibre). i,e, you're
    running Calibre in the background and let your skill running
    regardless whether calibre succeeded to run or not. So if you don't
    bother about communicating with your child process, why do you want to
    use the ipc functions ? I'm pretty much sure I'm missing something :-(

    I would advice the following in your case (This is an example):
    ; Print your calibre command into a string : calibreCommand
    sprintf(calibreCommand "/yourMgcInstallDir/bin/calibre -drc -hier -
    whateverOptionOrCtrlFile %s/%s.gds &" dirName cellName)
    system(calibreCommand)

    Anyway, This a little example about using IPCs

    ;-----------------------------------------------------------------
    ; Get The user name from unix
    cidUser = ipcBeginProcess("whoami")
    ipcWait(cidUser)
    ridUser=car(parseString(ipcReadProcess(cidUser) "\n"))

    ; Get The hostname from unix
    cidHost = ipcBeginProcess("uname -n")
    ipcWait(cidHost)
    ridHost=car(parseString(ipcReadProcess(cidHost) "\n"))
    ;-----------------------------------------------------------------

    I saw you are using csh() to run your Calibre and I guess it is for a
    purpose. In the case you move to ipc, you have to know that 'ipc' is
    not running commands under your default login shell even if the
    commands are passed through it, ipcBeginProcess executes commands
    using Bourne Shell (sh).

    BTW : What does it mean "... but behavior of my skill program is not
    as expected ! "

    Hope this help you !

    Interesting and Could be useful :
    Interprocess Communication SKILL Functions Reference -->
    $CDSHOME/doc/skipcref.pdf

    Riad.
     
    Riad KACED, May 8, 2008
    #3
  4. Riad KACED wrote, on 05/08/08 00:31:
    My guess is that he needs to know when it's finished - to do some further
    processing - but doesn't want the session to block.

    So something like:

    procedure(MYexitHandler(cid status)
    ... do the things you want to do when Calibre has finished ...
    )

    ; just to print any output from the command to the CIW
    procedure(MYdataHandler(cid data)
    printf("%s" data)
    )

    ipcBeginProcess("calibre ..." "" 'MYdataHandler 'MYdataHandler 'MYexitHandler)

    For every bit of output that the calibre command produces, it will call the data
    handler and print it. This happens asynchronously, so it doesn't block DFII.
    When the child process exits, the MYexitHandler function will get called, and
    then you can execute any further SKILL code you need - safe in the knowledge
    that the calibre job exited.

    Regards,

    Andrew.
     
    Andrew Beckett, May 8, 2008
    #4
  5. bedoune

    bedoune Guest

    hi,
    sorry, i'm late to asnwer :( but i was on holidays :)

    Minna-san, thanks a lot for your answers. I will try the code you sent
    me :)

    @Riad: What i mean by "behaviour is not as expected" is that in my
    program, after Calibre execution, i open the result files... if i put
    a "&", my program tries to open result files before their creation. So
    i get some error messages...

    thanks and regards,

    b.
     
    bedoune, May 14, 2008
    #5
  6. bedoune

    Riad KACED Guest

    Yes of course, that's a normal behaviour when you run your process in
    the Background.
    You definitely need to use the ipc functions as I mentioned before or
    as advised by Andrew.

    Riad.
     
    Riad KACED, May 15, 2008
    #6
  7. bedoune

    bedoune Guest

    Hello :)

    I restart to fight with my program ^^

    the solution proposed by Andrew works fine (arigatou Andrew-san!)
    but it does not work for all unix command ?

    I mean, before running my command "Calibre ..." i need to run a setup
    script, by sourcing it. if i don't source it, calibre doesn't run.

    so my full command is : "source Myfile ; Calibre ..."

    I realized that ipcBeginProcess runs command like "sh" command. I can
    not source any file with ipcBeginProcess nor sh.

    That's why, initially, i used the command "csh()" to execute my batch
    of commands (but freezes dfII during execution).

    So i tried things like :

    Com = "csh | source myfile && calibre ..."
    ipcBeginProcess(Com ...)

    or

    Com = "csh ; source myfile ; calibre ..."
    ipcBeginProcess(Com ...)


    do you have an idea on how to source my file, run calibre and using
    ipc at the same time ??

    thanks a lot for your help.

    regards,

    b.
     
    bedoune, Jun 16, 2008
    #7
  8. Use

    Com="csh -c 'source myfile ; calibre ...'"

    Andrew.
     
    Andrew Beckett, Jun 18, 2008
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.