Hi, I was wondering if it's possible to detect where the script was launched from. I need to be able to detect if the script was launched from the console window or from the window environment by using a shortcut or some GUI file manager.

The purpose is: If the program was launched from the console, it will be outputting directly to console. I mean, running with it's text version interface, but if it was launched from the GUI by a file manager or a shortcut, or whatever (NOT console), it will be launched in it's GUI Window (not text) interface with buttons etc.

I can't use ENV variable to test if it's console, because perl says that it's console, unless it's ran as a CGI.
And no, I don't want to pass parameters in the shortcut or the command line, to specify that it's GUI. I just want to be able to type or double-click on the script file.

I know that it's possible, because, a long time ago, a Creative sound card came with a music player with the drivers installation. It could launch a text version of the player in the dos window when you type it's executable from the dos window, but when it was launched from the file manager by double-clicking on the executable, it launched it's GUI version.

So, in other words, when the script detects that it was being typed in the console to launch, it will use console interface subroutine (STDIN/OUT, etc.), but when it detects that it was launched not from the console, it will go to the Tkx subroutine for the GUI interface.
Thanx.

In reply to Detect Environment by igoryonya

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.