[Vm-dev] Identify console executable and standard one

Eliot Miranda eliot.miranda at gmail.com
Sat Apr 14 22:23:13 UTC 2018


Hi Vincent,

On Sat, Apr 14, 2018 at 2:05 PM, <Vincent.Blondeau at lamresearch.com> wrote:

>
>
> Hi,
>
>
>
> I would like to know from inside the image whether the ST image is a
> console executable, e.g. PharoConsole.exe vs Pharo.exe (Related to this
> pull request: https://github.com/pharo-project/pharo/pull/694).
>
> The solution is to add a primitive inside the VM but I have no idea where
> I should look for…
>
> Could someone give me some pointers?
>

A quick hack would be to use system attribute 0, the name of the executable:

Smalltalk getSystemAttribute: 0
'/Users/eliot/oscogvm/build.macos64x64/squeak.cog.spur/Squeak.app/Contents/MacOS/Squeak'

and match for Console.exe.  A more thorough approach on unix is to test
stdin to see if it is attached to a tty.  Try this at a unix/macos terminal:

$ tty
/dev/ttys006
$ tty </dev/null
not a tty
$ man 3 ttyname
$ man 2 ioctl

I'm not sure how to do this on Windows.  I wrote this in
platforms/win32/vm/sqWin32Main.c::WinMain

#if 0 /* This way used to work.  Does no longer. */
  DWORD mode;

  fIsConsole = GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode);
#elif 0 /* This does /not/ work with STD_INPUT_HANDLE or STD_OUTPUT_HANDLE
*/
  CONSOLE_SCREEN_BUFFER_INFO csbi;

  if ((fIsConsole = GetConsoleScreenBufferInfo
                        (GetStdHandle(STD_INPUT_HANDLE), &csbi)))
        fIsConsole = csbi.dwCursorPosition.X || csbi.dwCursorPosition.Y;
#else /* This /does/ work; see */
    /*
https://stackoverflow.com/questions/9009333/how-to-check-if-the-program-is-run-from-a-console
*/
  HWND consoleWnd = GetConsoleWindow();
  DWORD dwProcessId;
  GetWindowThreadProcessId(consoleWnd, &dwProcessId);
  fIsConsole = GetCurrentProcessId() != dwProcessId;
#endif

but it seems like a hack to me.  I'd love to know what the approved future
proof way is.


>
> Thanks in advance!
>
>
>
> Cheers,
>
>
> *Vincent Blondeau *Software Engineer, Software and Controls | Global
> Product Group
> Desk +1 510.572.7499
>
>
>
> *Lam Research Corporation *4650 Cushing Pkwy, Fremont, CA 94538 USA |
> www.lamresearch.com
> Connect with Lam Research: Facebook
> <https://www.facebook.com/LamResearchCorporation> | Twitter
> <https://twitter.com/lamresearch> | LinkedIn
> <https://www.linkedin.com/company/lam-research>
>
>
>
>


-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20180414/d3b16ec5/attachment.html>


More information about the Vm-dev mailing list