Keep a shell open?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Keep a shell open?

Russell Haley
Weird late night question:

Is it possible to open a shell in a coroutine and just interact with
it when I need it?

So in a coroutine, I would just open it and then read and write then yield?

Cheers,

Russ

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

Dirk Laurie-2
The filehandle returned by io.popen can be read from
or written to, but not both.

2018-01-26 9:16 GMT+02:00 Russell Haley <[hidden email]>:

> Weird late night question:
>
> Is it possible to open a shell in a coroutine and just interact with
> it when I need it?
>
> So in a coroutine, I would just open it and then read and write then yield?
>
> Cheers,
>
> Russ
>

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

nobody
In reply to this post by Russell Haley
On 2018-01-26 08:16, Russell Haley wrote:
> Is it possible to open a shell in a coroutine and just interact with
> it when I need it?
>
> So in a coroutine, I would just open it and then read and write then
> yield?

As Dirk wrote, `io.popen` is read XOR write.

If you're on some unix-y system & depending on what you're doing,
lpty[1] might work for you.

There may be "simpler"[2] ways to do that, but so far, for me, this was
the "simplest"[3] way to get non-blocking bidirectional communication going.

-- nobody

[1] http://tset.de/lpty/index.html
     (also via `luarocks install lpty`)

[2] as in "not grabbing a PTY yadda yadda"

[3] as in "least amount of thinking/code & sufficiently portable (*nix)"

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

Joshua Jensen-2
In reply to this post by Russell Haley
Russell Haley wrote on 1/26/2018 12:16 AM:
> Is it possible to open a shell in a coroutine and just interact with
> it when I need it?
>
> So in a coroutine, I would just open it and then read and write then yield?
You imply you want asynchronous reads and writes here...?

Anyway, my go to, now called osprocess [1], for dealing with process
input and output is based on the old lua-ex module. I have used it with
success for years.

-Josh

[1]
https://github.com/jjensen/luaplus51-all/tree/master/Src/Modules/osprocess

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

Russell Haley
On Fri, Jan 26, 2018 at 7:54 AM, Joshua Jensen <[hidden email]> wrote:

> Russell Haley wrote on 1/26/2018 12:16 AM:
>>
>> Is it possible to open a shell in a coroutine and just interact with
>> it when I need it?
>>
>> So in a coroutine, I would just open it and then read and write then
>> yield?
>
> You imply you want asynchronous reads and writes here...?
>
> Anyway, my go to, now called osprocess [1], for dealing with process input
> and output is based on the old lua-ex module. I have used it with success
> for years.
>
> -Josh
>
> [1]
> https://github.com/jjensen/luaplus51-all/tree/master/Src/Modules/osprocess
>

Brilliant. osprocess + luash + powershell will make me very happy.
--forked from https://github.com/zserge/luash to add powershell support
https://github.com/WinLua/luash

I see you also have a dotnet module. Does this allow for running
managed .net assemblies directly in Lua?

Your LuaPlus project looks pretty amazing. It's more or less what I
want to do with WinLua (only yours is better). I didn't want to spend
the time integrating other packages so I was looking to include
luarocks with my installer.

Thanks,
Russ

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

Russell Haley
In reply to this post by nobody
On Fri, Jan 26, 2018 at 12:17 AM, nobody <[hidden email]> wrote:

> On 2018-01-26 08:16, Russell Haley wrote:
>>
>> Is it possible to open a shell in a coroutine and just interact with
>> it when I need it?
>>
>> So in a coroutine, I would just open it and then read and write then
>> yield?
>
>
> As Dirk wrote, `io.popen` is read XOR write.
>
> If you're on some unix-y system & depending on what you're doing,
> lpty[1] might work for you.
>
> There may be "simpler"[2] ways to do that, but so far, for me, this was
> the "simplest"[3] way to get non-blocking bidirectional communication going.
>
> -- nobody

Thanks, Dirk, Nobody. This was the answer I expected. The answer from
Josh is what I was hoping for. :)

> [1] http://tset.de/lpty/index.html
>     (also via `luarocks install lpty`)
>
> [2] as in "not grabbing a PTY yadda yadda"
>
> [3] as in "least amount of thinking/code & sufficiently portable (*nix)"
>

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

szbnwer@gmail.com
hi there :)

named pies can solve this i think, however, i dunno if windows have
anything like that, nor played with them cuz the lack of need in past
- so just a hint for an easy possibility in general...

all the bests! :)

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

szbnwer@gmail.com
> named pies can solve this i think, however, i dunno if windows have
*pipes

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

pocomane-2
In reply to this post by Joshua Jensen-2

On Fri, Jan 26, 2018 at 4:54 PM, Joshua Jensen <[hidden email]> wrote:
You imply you want asynchronous reads and writes here...?

Anyway, my go to, now called osprocess [1], for dealing with process input and output is based on the old lua-ex module. I have used it with success for years.

-Josh

[1] https://github.com/jjensen/luaplus51-all/tree/master/Src/Modules/osprocess


I have something similar too. It should work in lua 5.3 and luajit 2.1, linux and windows. I pushed it on luarocks too, but it is not tested a lot...

Reply | Threaded
Open this post in threaded view
|

Re: Keep a shell open?

pocomane
In reply to this post by Joshua Jensen-2

On Fri, Jan 26, 2018 at 4:54 PM, Joshua Jensen <[hidden email]> wrote:
You imply you want asynchronous reads and writes here...?

Anyway, my go to, now called osprocess [1], for dealing with process input and output is based on the old lua-ex module. I have used it with success for years.

-Josh

[1] https://github.com/jjensen/luaplus51-all/tree/master/Src/Modules/osprocess


I have something similar too. It should work in lua 5.3 and luajit 2.1, linux and windows. I pushed it on luarocks too, but it is not tested a lot...

Reply | Threaded
Open this post in threaded view
|

Renaming "Lunia" as "LuaPlusPlus"

Paige DePol
In reply to this post by Joshua Jensen-2
Joshua Jensen <[hidden email]> wrote:

> [1] https://github.com/jjensen/luaplus51-all/

Wow, Joshua, it looks like your LuaPlus will mix with my Lunia project quite
nicely. I am working on adding more C and C++ type features to Lua while you
have made a very nice interface to C++ objects directly... which is something
I would need to add as well, so it is nice to have some work be done already!

I have created quite a bit of framework around a defined object model for
Lua, along with other new features. Your project will be quite helpful for
me to hook those objects up to allow two-way access between C++ and my
object model. I will not be implementing all of C++ in Lua though, just the
bits I like and think could help, keeping in mind my goal is performance
improvement while keeping an eye on runtime bloat.

I had thought of using the name Lua++ for my project, but didn't know if the
name would go over well or not. However, I think I am going to use the name
as I intend for Lua++ to be to Lua what C++ was to C... even if that is not
necessarily seen as a good thing by some people! I already have a logo for
Lua++ as well... I rotated the moon in the Lua logo to be parallel with the
shadow and added a + inside each, I think it came out really well!

I searched for usage of Lua++ online and found an old project (named LuaPP)
that was referenced on this list back in 2011 which no longer seems to have
any active files under either GitHub profile. The only other reference is
another similarly abandoned SourceForge project with a single XML file as
the entire content of the project.

All other references to "LuaPP" seem to be for a preprocessor, or other
packages that are C++ to Lua bindings. As I do not see any current use of
the name Lua++, or LuaPlusPlus, I am going to adopt "LuaPlusPlus" as the
long-form written name of my project, and will also use "Lua++", the
binaries will be "lpp" and "lppc".

If me adopting the name "Lua++" or "LuaPlusPlus" is a problem for anyone on
the list please let me know now... but given that I can find nobody else who
is actively using the name I would really like to adopt it for my project!

~Paige