• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

12.9.3 Interacting with foreign streams
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • Foreign Language Interface
        • Foreign access to Prolog IO streams
          • Interacting with foreign streams
            • Sset_timeout()
            • Sunit_size()
            • Sputc()
            • Sgetc()
            • Sfgetc()
            • Sungetc()
            • Sputcode()
            • Sgetcode()
            • Speekcode()
            • Sputw()
            • Sgetw()
            • Sfread()
            • Sfwrite()
            • Sfeof()
            • Sfpasteof()
            • Ssetlocale()
            • Sflush()
            • Ssize()
            • Sseek()
            • Sseek64()
            • Stell()
            • Stell64()
            • Sclose()
            • Sgcclose()
            • Sfgets()
            • Sgets()
            • Sread_pending()
            • Spending()
            • Sfputs()
            • Sputs()
            • Sfprintf()
            • SfprintfX()
            • Sprintf()
            • Svprintf()
            • Ssprintf()
            • Ssnprintf()
            • SsnprintfX()
            • Svsprintf()
            • Svsnprintf()
            • Sdprintf()
            • SdprintfX()
            • Svdprintf()
            • Slock()
            • StryLock()
            • Sunlock()
            • Sfileno()
            • Swinsock()
            • Sclosehook()
            • Sset_filter()
            • Ssetbuffer()
            • Running a child process on a Windows terminal
              • Swinpseudoconsole()
              • Swinrelease_pseudoconsole()
              • Swinpseudoconsole_attributes()
              • Swinfree_pseudoconsole_attributes()
            • Writing Prolog terms to foreign streams
    • Packages

12.9.3.1 Running a child process on a Windows terminal

A child process gets a terminal on Windows by attaching to a pseudo console. The Epilog window (see swipl-win.exe) has no console of its own: it talks to its Prolog thread over two pipes, and a child handed those has nothing that echoes what it reads, no window size and no way to be interrupted. The functions below put such a child on the console of the terminal behind a stream. This is what shell/1 does, and what process_create/3 does for the streams the caller left alone. They exist on Windows only.

HANDLE Swinpseudoconsole(IOSTREAM *s)
Claim the pseudo console of the terminal behind s, or NULL if it has none to give. This is a claim rather than a query: the console reads and writes the same pipe ends as the stream, so the terminal runs one only while a client holds it, and the holder must touch neither the stream nor its companions meanwhile. Declared HANDLE because HPCON postdates SWI-Stream.h; they are the same.
void Swinrelease_pseudoconsole(IOSTREAM *s)
Hand the console back once the child is gone. The terminal closes it when the last client has released it.
void * Swinpseudoconsole_attributes(HANDLE hpcon)
Process attribute list that puts a child on hpcon, or NULL if it cannot be built. Pass it as the lpAttributeList of a STARTUPINFOEXW and create the process with EXTENDED_STARTUPINFO_PRESENT. Not with CREATE_NO_WINDOW: that asks for a console of the child's own, which is the opposite of what the attribute says and wins.
void Swinfree_pseudoconsole_attributes(void *attributes)
Free the list once the child is created. The console itself is held until Swinrelease_pseudoconsole().

ClioPatria (version V3.1.1-59-g7b9a7a3)