Directing the result from a procedure to a file (with in icfb window).

Discussion in 'Cadence' started by kamesh, Sep 3, 2006.

  1. kamesh

    kamesh Guest

    Dear all,

    I have a procedure say print_all_lists() in one of the skill files.
    When I execute it in icfb window I get the result. But I would like to
    capture that result from icfb window. can any one let me know how I can
    direct the result to a file from the icfb window.

    Thanks and Regards,
    Kamesh.
     
    kamesh, Sep 3, 2006
    #1
  2. kamesh

    Jimka Guest

    hi kamesh, you should be able to use a macro such as the
    following for your purpose.

    (defmacro withStdoutToFile (t_file @rest body)
    `(let ((stdout (outfile t_file "w")))
    (unless stdout
    (error "cannot write to %L" ,t_file))
    (progn ,@body)
    (close stdout)))



    use it like this.

    (withStdoutToFile "/tmp/myfile"
    (print_all_lists))

    or in C-style parens
    withStdoutToFile("/tmp/myfile"
    print_all_lists())


    you can put as much code or as many function calls as you like inside
    the withOutputToFile body. And you can wrap the call to
    withOutputToFile
    around any of your code without affecting the return value of the code.

    does this help?
     
    Jimka, Sep 3, 2006
    #2
  3. kamesh

    Jimka Guest

    hi kamesh, you should be able to use a macro such as the
    following for your purpose.

    (defmacro withStdoutToFile (t_file @rest body)
    `(let ((stdout (outfile t_file "w")))
    (unless stdout
    (error "cannot write to %L" ,t_file))
    (progn ,@body)
    (close stdout)))



    use it like this.

    (withStdoutToFile "/tmp/myfile"
    (print_all_lists))

    or in C-style parens

    withStdoutToFile("/tmp/myfile"
    print_all_lists())


    you can put as much code or as many function calls as you like inside
    the withStdoutToFile body. And you can wrap the call to
    withStdoutToFile
    around any of your code without affecting the return value of the code.

    does this help?
     
    Jimka, Sep 3, 2006
    #3
  4. kamesh

    jayl-news Guest

    Jimka, I've been writing SKILL since about 1985, and that
    is a cool little hack. Ya' learn something new every day
    (if you're lucky)!

    -Jay-
     
    jayl-news, Sep 4, 2006
    #4
  5. kamesh

    Jimka Guest

    hi Jay, i'm glad you like it. There are lots of cool
    things about SKILL when you start thinking of it as
    lisp. With-style macros are easy in lisp but horribly
    difficult in languages such as Java, Python, Perl, C++
    etc.

    -jim
     
    Jimka, Sep 4, 2006
    #5
  6. kamesh

    kamesh Guest

    Thanks a lot Jimka. That worked like a charm. :)

    Regards,
    Kamesh.
     
    kamesh, Sep 5, 2006
    #6
  7. Whilst Jim's approach is a neat way of doing this, another simple approach is
    to just do:

    hiStartLog("filename")
    your_function()
    hiEndLog()

    It's not exactly the same - in that you get all the tags in the file (like you
    do in the CDS.log file) - but it's often sufficient.

    Just depends on what you're trying to achieve!

    I prefer to write functions that are likely to want to write to a file, so
    that they do something like this:

    procedure(MYfunc(@optional (port stdout))
    fprintf(port "....")
    )

    i.e. use fprintf instead of printf, and have an optional arg which is the port
    to write to, which defaults to stdout.

    In other words, anticipate the fact that you might want to redirect the output,
    rather than trying to fix it afterwards.

    Andrew.
     
    Andrew Beckett, Sep 6, 2006
    #7
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.