<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hi Alistair,<br></div><div><br>On Apr 15, 2018, at 12:17 AM, Alistair Grant <<a href="mailto:akgrant0710@gmail.com">akgrant0710@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><span></span><br><span>Hi Vincent,</span><br><span></span><br><span>On 15 April 2018 at 00:23, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:</span><br><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Hi Vincent,</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>On Sat, Apr 14, 2018 at 2:05 PM, <<a href="mailto:Vincent.Blondeau@lamresearch.com">Vincent.Blondeau@lamresearch.com</a>> wrote:</span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Hi,</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>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">https://github.com/pharo-project/pharo/pull/694</a>).</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>The solution is to add a primitive inside the VM but I have no idea where I should look for…</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Could someone give me some pointers?</span><br></blockquote></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>A quick hack would be to use system attribute 0, the name of the executable:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Smalltalk getSystemAttribute: 0 '/Users/eliot/oscogvm/build.macos64x64/squeak.cog.spur/Squeak.app/Contents/MacOS/Squeak'</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>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:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>$ tty</span><br></blockquote><blockquote type="cite"><span>/dev/ttys006</span><br></blockquote><blockquote type="cite"><span>$ tty </dev/null</span><br></blockquote><blockquote type="cite"><span>not a tty</span><br></blockquote><blockquote type="cite"><span>$ man 3 ttyname</span><br></blockquote><blockquote type="cite"><span>$ man 2 ioctl</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>I'm not sure how to do this on Windows.  I wrote this in platforms/win32/vm/sqWin32Main.c::WinMain</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>#if 0 /* This way used to work.  Does no longer. */</span><br></blockquote><blockquote type="cite"><span>  DWORD mode;</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>  fIsConsole = GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode);</span><br></blockquote><blockquote type="cite"><span>#elif 0 /* This does /not/ work with STD_INPUT_HANDLE or STD_OUTPUT_HANDLE */</span><br></blockquote><blockquote type="cite"><span>  CONSOLE_SCREEN_BUFFER_INFO csbi;</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>  if ((fIsConsole = GetConsoleScreenBufferInfo</span><br></blockquote><blockquote type="cite"><span>                        (GetStdHandle(STD_INPUT_HANDLE), &csbi)))</span><br></blockquote><blockquote type="cite"><span>        fIsConsole = csbi.dwCursorPosition.X || csbi.dwCursorPosition.Y;</span><br></blockquote><blockquote type="cite"><span>#else /* This /does/ work; see */</span><br></blockquote><blockquote type="cite"><span>    /* <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> */</span><br></blockquote><blockquote type="cite"><span>  HWND consoleWnd = GetConsoleWindow();</span><br></blockquote><blockquote type="cite"><span>  DWORD dwProcessId;</span><br></blockquote><blockquote type="cite"><span>  GetWindowThreadProcessId(consoleWnd, &dwProcessId);</span><br></blockquote><blockquote type="cite"><span>  fIsConsole = GetCurrentProcessId() != dwProcessId;</span><br></blockquote><blockquote type="cite"><span>#endif</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>but it seems like a hack to me.  I'd love to know what the approved future proof way is.</span><br></blockquote><span></span><br><span>If you want to test it, the results of similar code is currently</span><br><span>available from within the image:</span><br><span></span><br><span>SQFile.isStdioStream for stdin notionally provides the information.</span><br><span></span><br><span>On Unix it is set in sqFileStdioHandlesInto() in sqFilePluginBasicPrims.c:</span><br><span></span><br><span>files[0].sessionID = thisSession;</span><br><span>files[0].file = stdin;</span><br><span>files[0].writable = false;</span><br><span>files[0].lastOp = READ_OP;</span><br><span>files[0].isStdioStream = isatty(fileno(stdin));</span><br><span>files[0].lastChar = EOF;</span><br><span></span><br><span></span><br><span>On Windows in sqFileStdioHandlesInto() in sqWin32FilePrims.c:</span><br><span></span><br><span>files[0].sessionID = thisSession;</span><br><span>files[0].file = GetStdHandle(STD_INPUT_HANDLE);</span><br><span>files[0].writable = false;</span><br><span>files[0].lastOp = 0; /* unused on win32 */</span><br><span>files[0].</span><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">isStdioStream </span></font>= GetConsoleMode(files[0].file, &mode) != 0;</div></blockquote><blockquote type="cite"><div><span>AddHandleToTable(win32Files, files[0].file);</span><br></div></blockquote><div><br></div>This could be causing problems, because AFAIA <span style="background-color: rgba(255, 255, 255, 0);">GetConsoleMode(files[0].file, &mode) is no longer reliable.  Can you test?</span><div><br></div><div>- test a non-console vm launched from a console window and from the desktop; <span style="background-color: rgba(255, 255, 255, 0);">isStdioStream should be false</span></div><div>- test a console vm launched from a console; <span style="background-color: rgba(255, 255, 255, 0);">isStdioStream should be true</span></div><div>- test a console vm launched from the desktop; <span style="background-color: rgba(255, 255, 255, 0);">isStdioStream should be false</span></div><div><br></div><div>Right?</div><div><br><blockquote type="cite"><div><span></span><span>And SQFile is the byte array handle used in the file streams.</span><br><span></span><br><span>I've been thinking that it would be nice to be able to access the</span><br><span>structure from within the image, but haven't yet come up with a way to</span><br><span>automatically map the fields (Monty did some work which might help,</span><br><span>but I haven't looked at it yet).</span><br></div></blockquote><div><br></div>We could simply add a primitive primitiveDescriptorIsATTY or some such.</div><div><br><blockquote type="cite"><div><span></span><span>Cheers,</span><br><span>Alistair</span><br></div></blockquote></div></body></html>