Hi,

So I had a pipeline recently that someone was running when they got an error, which the ostensibly emailed to me without alteration. The error looked like it was from the first script call in the pipeline because there should have been an echo in between the 2 calls - at least from what I saw pasted in the email. It turned out that the error was from the second script call in the pipeline.

I have a debug mode in which any error gets prepended with the script's name, but you have to explicitly supply a --debug flag and I was thinking that it would be nice if my script could detect when it's immediate parent process is not an interactive tty - and decide to prepend that string automatically.

In an ideal world, it would also be able to tell if it is inside a series of piped commands as opposed to redirected input/output (</>). Theoretically, I would think that this could be possible simply by the number of concurrent processes the parent process has.

However, I feel like both of these things would be very non-trivial to implement. I know I can use -t or -p for piping, but those don't know anything about parent processes and can't tell the difference between | vs. >.

Any thoughts?

Thanks,

Rob


In reply to Can a script tell if it is being run from inside a script versus in an interactive terminal session? by hepcat72

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.