Challenge: who can background this shell command?

David Bovill david.bovill at gmail.com
Thu Aug 1 11:12:28 EDT 2019


OK - so I have it working by writing to a temporary file.

Trying to redirect the output to stdout - so that shell() return the
information of the background process - but this freezes:


   - *put* shell ("hugo server 2>&1 &") into launchResult

Even though:


   - command 2>&1 &

redirects stderr to stdout?

This is a working solution which writes to a temporary file - then reads
from that file till the end of the message in order to get hold of the
result:

> *command* hugo_BackgroundServer projectName
> *    put* env_GetFolder (projectName) into projectFolder
>     *set* the defaultfolder to projectFolder
>
> *--*    *put* the tempname & ".txt" into someFile
>     *put* "hugo server >" && someFile && "2>&1 &" into tShell
>     *put* shell (tShell) into shellResult
>
> *-- can take some time to start up so let's read from file till the end*
>   _ReadFromFile someFile
>     *put* the result into fileContents
>     *return* fileContents
> *end* hugo_BackgroundServer
>


> *private* *command* _ReadFromFile someFile
>     *open* file someFile for
> *read*    *read* from file someFile until "Press Ctrl+C to stop"
>     *put* it into fileContents
>     *close* file someFile
>     *return* fileContents
> *end* _ReadFromFile


On Thu, 1 Aug 2019 at 14:55, Matthias Rebbe via use-livecode <
use-livecode at lists.runrev.com> wrote:

> put "/users/matthias/downloads/temp/MailHog >
> /users/matthias/downloads/temp/hubbabubba.txt 2>&1 &" into tShell
>
> -- above redirects into file and then don´t ask me.. ;)
> put shell(tShell)
> answer URL "file:/users/matthias/downloads/temp/hubbabubba.txt"
> -- answer dialog shows content of file, which contains in my case the
> address and port it was binded to.
>
>
> 2019/08/01 15:46:01 Using in-memory storage
> 2019/08/01 15:46:01 [SMTP] Binding to address: 0.0.0.0:1025
> [HTTP] Binding to address: 0.0.0.0:8025
> 2019/08/01 15:46:01 Serving under http://0.0.0.0:8025/ <
> http://0.0.0.0:8025/>
> Creating API v1 with WebPath:
> Creating API v2 with WebPath:
> [APIv2] GET /api/v2/messages
> [APIv2] GET /api/v2/jim
> [APIv2] GET /api/v2/websocket
> [APIv1] KEEPALIVE /api/v1/events
>
>
> Be aware, that the background process runs untill you kill it from the
> shell.
>
> Regards,
>
> Matthias
>
>
> Matthias Rebbe
>
> free tools for Livecoders:
> InstaMaker <https://instamaker.dermattes.de/>
> WinSignMaker Mac <https://winsignhelper.dermattes.de/>
>
> > Am 01.08.2019 um 15:20 schrieb David Bovill via use-livecode <
> use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>>:
> >
> > That works in the message box - thanks Matthias.
> >
> > The only thing is I can't (yet) tell what port the server is running on
> - I
> > can see from the terminal (using pgrep) the process id of the started
> > server - but it does not appear to be serving correctly on the default
> > server port...
> >
> > Do you think there is a way to redirect the output to Livecode's result
> or
> > it variable - I seem to remember that there have been some changes to
> that
> > to make such a construction possible in Livecode - alternatively maybe
> the
> > output can be directed to a temporary file instead of " /dev/null"???
> >
> > Nearly there :)
> >
>
>
>
> Matthias Rebbe
>
> free tools for Livecoders:
> InstaMaker <https://instamaker.dermattes.de/>
> WinSignMaker Mac <https://winsignhelper.dermattes.de/>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the Use-livecode mailing list