Coder Social home page Coder Social logo

Close stdin about erlexec HOT 11 CLOSED

saleyn avatar saleyn commented on August 15, 2024
Close stdin

from erlexec.

Comments (11)

saleyn avatar saleyn commented on August 15, 2024

This is currently not supported. I am not sure if closing the pipe's output end of the parent process (erlexec) will in fact signal the end of file in the spawned child (tac). The first example is different from the second, because in the second case the tac is invoked by the command shell via popen() versus execv() invocation in the first case.

You can try to introduce a new command in exec.cpp that will lookup the pid of the child process state, close the writing end of the pipe, and see if it triggers the OS to close the corresponding stdin end of the pipe in the child process. If so, you are welcome to send a PR.

from erlexec.

pichi avatar pichi commented on August 15, 2024

The first example is different from the second, because in the second case the tac is invoked by the command shell via popen() versus execv() invocation in the first case.

It is actually exact way how the shell is doing it. It opens pipe by popen() and then it calls execve() in child. How do you think shell executes tac? :-)

from erlexec.

saleyn avatar saleyn commented on August 15, 2024

I would think the shell does it differently - via the pipe/fork/exec combination since popen() only returns a stream, and as the result the child is already spawned so there's no need to call execve() explicitly. I haven't looked at the library sources for the popen(), but I am nearly certain that it's got the execve() call in its implementation.

from erlexec.

pichi avatar pichi commented on August 15, 2024

From the manual:

The popen() function opens a process by creating a pipe, forking, and invoking the shell.

popen() is just a function which does all those steps for you but the mechanism behind is exactly same.

from erlexec.

pichi avatar pichi commented on August 15, 2024

For example: http://cnds.eecs.jacobs-university.de/courses/os-2010/src/popen/popen.c

from erlexec.

pichi avatar pichi commented on August 15, 2024

From BSD: http://www.retro11.de/ouxr/211bsd/usr/src/lib/libc/gen/popen.c.html

Exactly same shit :)

from erlexec.

pichi avatar pichi commented on August 15, 2024

Unfortunately, I'm not familiar with C++ only C.

from erlexec.

pichi avatar pichi commented on August 15, 2024

Nice:

1> application:start(erlexec).
ok
2> Watcher = spawn(fun F() -> receive Msg -> io:format("Got: ~p~n", [Msg]), F() end end).
<0.112.0>
3> {ok, Pid, OsPid} = exec:run("tac", [stdin, {stdout, Watcher}, {stderr, Watcher}]).
{ok,<0.114.0>,26143}
4> exec:send(Pid, <<"foo\n">>).
ok
5> exec:send(Pid, <<"bar\n">>).
ok
6> exec:send(Pid, <<"baz\n">>).
ok
7> exec:send(Pid, eof).
ok
Got: {stdout,26143,<<"baz\nbar\nfoo\n">>}

from erlexec.

pichi avatar pichi commented on August 15, 2024

I can't get it why they can't implement it in Erlang OTP as well.

from erlexec.

pichi avatar pichi commented on August 15, 2024

13 tests, 0 failures :)

from erlexec.

saleyn avatar saleyn commented on August 15, 2024

Yes, that exec:send(Pid, eof). makes sense, since it signifies the consumer's end of an end of input.

from erlexec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.