<div dir="ltr">Hi Vincent,<div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 14, 2018 at 2:05 PM,  <span dir="ltr"><<a href="mailto:Vincent.Blondeau@lamresearch.com" target="_blank">Vincent.Blondeau@lamresearch.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> <br>





<div lang="EN-US">
<div class="gmail-m_6659426987241379527WordSection1">
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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:
<a href="https://github.com/pharo-project/pharo/pull/694" target="_blank">https://github.com/pharo-<wbr>project/pharo/pull/694</a>).<u></u><u></u></p>
<p class="MsoNormal">The solution is to add a primitive inside the VM but I have no idea where I should look for…<u></u><u></u></p>
<p class="MsoNormal">Could someone give me some pointers?</p></div></div></blockquote><div><br></div><div>A quick hack would be to use system attribute 0, the name of the executable:</div><div><br></div><div>Smalltalk getSystemAttribute: 0 '/Users/eliot/oscogvm/build.macos64x64/squeak.cog.spur/Squeak.app/Contents/MacOS/Squeak'</div><div><br></div><div>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:</div><div><br></div><div>$ tty</div><div><div>/dev/ttys006</div><div>$ tty </dev/null<br></div><div>not a tty</div></div><div>$ man 3 ttyname</div><div>$ man 2 ioctl</div><div><br></div><div>I'm not sure how to do this on Windows.  I wrote this in platforms/win32/vm/sqWin32Main.c::WinMain</div><div><br></div><div><div>#if 0 /* This way used to work.  Does no longer. */</div><div>  DWORD mode;</div><div><br></div><div>  fIsConsole = GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode);</div><div>#elif 0 /* This does /not/ work with STD_INPUT_HANDLE or STD_OUTPUT_HANDLE */</div><div>  CONSOLE_SCREEN_BUFFER_INFO csbi;</div><div><br></div><div>  if ((fIsConsole = GetConsoleScreenBufferInfo</div><div>                        (GetStdHandle(STD_INPUT_HANDLE), &csbi)))</div><div>        fIsConsole = csbi.dwCursorPosition.X || csbi.dwCursorPosition.Y;</div><div>#else /* This /does/ work; see */</div><div>    /* <a href="https://stackoverflow.com/questions/9009333/how-to-check-if-the-program-is-run-from-a-console">https://stackoverflow.com/questions/9009333/how-to-check-if-the-program-is-run-from-a-console</a> */</div><div>  HWND consoleWnd = GetConsoleWindow();</div><div>  DWORD dwProcessId;</div><div>  GetWindowThreadProcessId(consoleWnd, &dwProcessId);</div><div>  fIsConsole = GetCurrentProcessId() != dwProcessId;</div><div>#endif</div></div><div><br></div><div>but it seems like a hack to me.  I'd love to know what the approved future proof way is.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="gmail-m_6659426987241379527WordSection1"><p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks in advance!<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:10.5pt;color:gray">Vincent Blondeau
<br>
</span></b><span style="font-size:10.5pt;color:gray">Software Engineer, Software and Controls | Global Product Group
<br>
Desk +1 510.572.7499<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.5pt;color:gray"><br>
<b>Lam Research Corporation<br>
</b>4650 Cushing Pkwy, Fremont, CA 94538 USA | <a href="http://www.lamresearch.com" target="_blank">www.lamresearch.com</a></span><span style="font-size:10.5pt;color:rgb(0,45,154)"><br>
</span><span style="font-size:10.5pt;color:gray">Connect with Lam Research: <a href="https://www.facebook.com/LamResearchCorporation" target="_blank">
Facebook</a> | <a href="https://twitter.com/lamresearch" target="_blank">Twitter</a> | <a href="https://www.linkedin.com/company/lam-research" target="_blank">
LinkedIn</a><br>
<br>
</span><span style="font-size:9pt;color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>

<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>