{"id":32214560,"url":"https://github.com/opensuse/mojo-ioloop-readwriteprocess","last_synced_at":"2026-03-16T11:31:57.497Z","repository":{"id":43711738,"uuid":"103239025","full_name":"openSUSE/Mojo-IOLoop-ReadWriteProcess","owner":"openSUSE","description":"Execute external programs or internal code blocks as separate process","archived":false,"fork":false,"pushed_at":"2025-04-08T08:28:53.000Z","size":648,"stargazers_count":11,"open_issues_count":5,"forks_count":15,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-10-22T07:07:49.392Z","etag":null,"topics":["cgroups","eventemitter","hacktoberfest","ioloop","mojo","process-manager","subreaper"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openSUSE.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-12T07:44:43.000Z","updated_at":"2025-07-10T21:05:01.000Z","dependencies_parsed_at":"2023-12-01T18:42:56.873Z","dependency_job_id":"8ec5e04f-ba7b-4c90-a5aa-184248b0a101","html_url":"https://github.com/openSUSE/Mojo-IOLoop-ReadWriteProcess","commit_stats":{"total_commits":341,"total_committers":15,"mean_commits":"22.733333333333334","dds":"0.42815249266862165","last_synced_commit":"f04eb4e5320fc5ee254cb12c018a419d20c96b92"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/openSUSE/Mojo-IOLoop-ReadWriteProcess","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openSUSE%2FMojo-IOLoop-ReadWriteProcess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openSUSE%2FMojo-IOLoop-ReadWriteProcess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openSUSE%2FMojo-IOLoop-ReadWriteProcess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openSUSE%2FMojo-IOLoop-ReadWriteProcess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openSUSE","download_url":"https://codeload.github.com/openSUSE/Mojo-IOLoop-ReadWriteProcess/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openSUSE%2FMojo-IOLoop-ReadWriteProcess/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280396136,"owners_count":26323639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cgroups","eventemitter","hacktoberfest","ioloop","mojo","process-manager","subreaper"],"created_at":"2025-10-22T07:06:37.562Z","updated_at":"2025-10-22T07:10:16.284Z","avatar_url":"https://github.com/openSUSE.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Coverage Status](http://codecov.io/github/openSUSE/Mojo-IOLoop-ReadWriteProcess/coverage.svg?branch=master)](https://codecov.io/github/openSUSE/Mojo-IOLoop-ReadWriteProcess?branch=master) [![Unit and integration tests](https://github.com/openSUSE/Mojo-IOLoop-ReadWriteProcess/actions/workflows/ci-tests.yaml/badge.svg)](https://github.com/openSUSE/Mojo-IOLoop-ReadWriteProcess/actions/workflows/ci-tests.yaml)\n# NAME\n\nMojo::IOLoop::ReadWriteProcess - Execute external programs or internal code blocks as separate process.\n\n# SYNOPSIS\n\n    use Mojo::IOLoop::ReadWriteProcess;\n\n    # Code fork\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(sub { print \"Hello\\n\" });\n    $process-\u003estart();\n    print \"Running\\n\" if $process-\u003eis_running();\n    $process-\u003egetline(); # Will return \"Hello\\n\"\n    $process-\u003epid(); # Process id\n    $process-\u003estop();\n    $process-\u003ewait_stop(); # if you intend to wait its lifespan\n\n    # Methods can be chained, thus this is valid:\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $output = process( sub { print \"Hello\\n\" } )-\u003estart()-\u003ewait_stop-\u003egetline;\n\n    # Handles seamelessy also external processes:\n    my $process = process(execute=\u003e '/path/to/bin' )-\u003eargs([qw(foo bar baz)]);\n    $process-\u003estart();\n    my $line_output = $process-\u003egetline();\n    my $pid = $process-\u003epid();\n    $process-\u003estop();\n    my @errors = $process-\u003eerror;\n\n    # To help when debugging Mojo::Collections\n    use Mojo::Util qw(dumper);\n    my $errors = dumper $process-\u003eerror-\u003eto_array;\n\n    # Get process return value\n    $process = process( sub { return \"256\"; } )-\u003estart()-\u003ewait_stop;\n    # We need to stop it to retrieve the exit status\n    my $return = $process-\u003ereturn_status;\n\n    # We can access directly to handlers from the object:\n    my $stdout = $process-\u003eread_stream;\n    my $stdin = $process-\u003ewrite_stream;\n    my $stderr = $process-\u003eerror_stream;\n\n    # So this works:\n    print $stdin \"foo bar\\n\";\n    my @lines = \u003c$stdout\u003e;\n\n    # There is also an alternative channel of communication (just for forked processes):\n    my $channel_in = $process-\u003echannel_in; # write to the child process\n    my $channel_out = $process-\u003echannel_out; # read from the child process\n    $process-\u003echannel_write(\"PING\"); # convenience function\n\n# DESCRIPTION\n\nMojo::IOLoop::ReadWriteProcess is yet another process manager.\n\n# EVENTS\n\n[Mojo::IOLoop::ReadWriteProcess](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess) inherits all events from [Mojo::EventEmitter](https://metacpan.org/pod/Mojo%3A%3AEventEmitter) and can emit\nthe following new ones.\n\n## start\n\n    $process-\u003eon(start =\u003e sub {\n      my ($process) = @_;\n      $process-\u003eis_running();\n    });\n\nEmitted when the process starts.\n\n## stop\n\n    $process-\u003eon(stop =\u003e sub {\n      my ($process) = @_;\n      $process-\u003erestart();\n    });\n\nEmitted when the process stops.\n\n## process\\_error\n\n    $process-\u003eon(process_error =\u003e sub {\n      my ($e) = @_;\n      my @errors = @{$e};\n    });\n\nEmitted when the process produce errors.\n\n## process\\_stuck\n\n    $process-\u003eon(process_stuck =\u003e sub {\n      my ($self) = @_;\n      ...\n    });\n\nEmitted when `blocking_stop` is set and all attempts for killing the process\nin `max_kill_attempts` have been exhausted.\nThe event is emitted before attempting to kill it with SIGKILL and becoming blocking.\n\n## SIG\\_CHLD\n\n    $process-\u003eon(SIG_CHLD =\u003e sub {\n      my ($self) = @_;\n      ...\n    });\n\nEmitted when we receive SIG\\_CHLD.\n\n## SIG\\_TERM\n\n    $process-\u003eon(SIG_TERM =\u003e sub {\n      my ($self) = @_;\n      ...\n    });\n\nEmitted when the child forked process receives SIG\\_TERM, before exiting.\n\n## collected\n\n    $process-\u003eon(collected =\u003e sub {\n      my ($self) = @_;\n      ...\n    });\n\nEmitted right after status collection.\n\n## collect\\_status\n\n    $process-\u003eon(collect_status =\u003e sub {\n      my ($self) = @_;\n      ...\n    });\n\nEmitted when on child process waitpid.\nIt is used internally to get the child process status.\nNote: events attached to it are wiped when process has been stopped.\n\n# ATTRIBUTES\n\n[Mojo::IOLoop::ReadWriteProcess](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess) inherits all attributes from [Mojo::EventEmitter](https://metacpan.org/pod/Mojo%3A%3AEventEmitter) and implements\nthe following new ones.\n\n## execute\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(execute =\u003e \"/usr/bin/perl\");\n    $process-\u003estart();\n    $process-\u003eon( stop =\u003e sub { print \"Process: \".(+shift()-\u003epid).\" finished\"; } );\n    $process-\u003estop();\n\n`execute` should contain the external program that you wish to run.\n\n## code\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(code =\u003e sub { print \"Hello\" } );\n    $process-\u003estart();\n    $process-\u003eon( stop =\u003e sub { print \"Process: \".(+shift()-\u003epid).\" finished\"; } );\n    $process-\u003estop();\n\nIt represent the code you want to run in background.\n\nYou do not need to specify `code`, it is implied if no arguments is given.\n\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(sub { print \"Hello\" });\n    $process-\u003estart();\n    $process-\u003eon( stop =\u003e sub { print \"Process: \".(+shift()-\u003epid).\" finished\"; } );\n    $process-\u003estop();\n\n## args\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(code =\u003e sub { print \"Hello \".$_[1] }, args =\u003e \"User\" );\n    $process-\u003estart();\n    $process-\u003eon( stop =\u003e sub { print \"Process: \".(+shift()-\u003epid).\" finished\"; } );\n    $process-\u003estop();\n\n    # The process will print \"Hello User\"\n\nArguments pass to the external binary or the code block. Use arrayref to pass many.\n\n## blocking\\_stop\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(code =\u003e sub { print \"Hello\" }, blocking_stop =\u003e 1 );\n    $process-\u003estart();\n    $process-\u003eon( stop =\u003e sub { print \"Process: \".(+shift()-\u003epid).\" finished\"; } );\n    $process-\u003estop(); # Will wait indefinitely until the process is stopped\n\nSet it to 1 if you want to do blocking stop of the process.\n\n## channels\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(code =\u003e sub { print \"Hello\" }, channels =\u003e 0 );\n    $process-\u003estart();\n    $process-\u003eon( stop =\u003e sub { print \"Process: \".(+shift()-\u003epid).\" finished\"; } );\n    $process-\u003estop(); # Will wait indefinitely until the process is stopped\n\nSet it to 0 if you want to disable internal channels.\n\n## session\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(sub { print \"Hello\" });\n    my $session = $process-\u003esession;\n    $session-\u003eenable_subreaper;\n\nReturns the current [Mojo::IOLoop::ReadWriteProcess::Session](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess%3A%3ASession) singleton.\n\n## subreaper\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(code =\u003e sub { print \"Hello \".$_[1] }, args =\u003e \"User\" );\n    $process-\u003esubreaper(1)-\u003estart();\n    $process-\u003eon( stop =\u003e sub { shift()-\u003edisable_subreaper } );\n    $process-\u003estop();\n\n    # The process will print \"Hello User\"\n\nMark the current process (not the child) as subreaper on start.\nIt's on invoker behalf to disable subreaper when process stops, as it marks the current process and not the\nchild.\n\n## ioloop\n\n    my $loop    = $process-\u003eioloop;\n    $subprocess = $process-\u003eioloop(Mojo::IOLoop-\u003enew);\n\nEvent loop object to control, defaults to the global [Mojo::IOLoop](https://metacpan.org/pod/Mojo%3A%3AIOLoop) singleton.\n\n## max\\_kill\\_attempts\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(code =\u003e sub { print \"Hello\" }, max_kill_attempts =\u003e 50 );\n    $process-\u003estart();\n    $process-\u003eon( stop =\u003e sub { print \"Process: \".(+shift()-\u003epid).\" finished\"; } );\n    $process-\u003estop(); # It will attempt to send SIGTERM 50 times.\n\nDefaults to `5`, is the number of attempts before bailing out.\n\nIt can be used with blocking\\_stop, so if the number of attempts are exhausted,\na SIGKILL and waitpid will be tried at the end.\n\n## kill\\_whole\\_group\n\n    use Mojo::IOLoop::ReadWriteProcess;\n    my $process = Mojo::IOLoop::ReadWriteProcess-\u003enew(code =\u003e sub { setpgrp(0, 0); exec(...); }, kill_whole_group =\u003e 1 );\n    $process-\u003estart();\n    $process-\u003esend_signal(...); # Will skip the usual check whether $process-\u003epid is running\n    $process-\u003estop();           # Kills the entire process group and waits for all processes in the group to finish\n\nDefaults to `0`, whether to send signals (e.g. to stop) to the entire process group.\n\nThis is useful when the sub process creates further sub processes and creates a new process\ngroup as shown in the example. In this case it might be useful to take care of the entire process\ngroup when stopping and wait for every process in the group to finish.\n\n## collect\\_status\n\nDefaults to `1`, If enabled it will automatically collect the status of the children process.\nDisable it in case you want to manage your process child directly, and do not want to rely on\nautomatic collect status. If you won't overwrite your `SIGCHLD` handler,\nthe `SIG_CHLD` event will be still emitted.\n\n## serialize\n\nDefaults to `0`, If enabled data returned from forked process will be serialized with Storable.\n\n## kill\\_sleeptime\n\nDefaults to `1`, it's the seconds to wait before attempting SIGKILL when blocking\\_stop is set to 1.\n\n## separate\\_err\n\nDefaults to `1`, it will create a separate channel to intercept process STDERR,\notherwise it will be redirected to STDOUT.\n\n## verbose\n\nDefaults to `1`, it indicates message verbosity.\n\n## set\\_pipes\n\nDefaults to `1`, If enabled, additional pipes for process communication are automatically set up.\n\n## internal\\_pipes\n\nDefaults to `1`, If enabled, additional pipes for retreiving process return and errors are set up.\nNote: If you disable that, the only information provided by the process will be the exit\\_status.\n\n## autoflush\n\nDefaults to `1`, If enabled autoflush of handlers is enabled automatically.\n\n## error\n\nReturns a [Mojo::Collection](https://metacpan.org/pod/Mojo%3A%3ACollection) of errors.\nNote: errors that can be captured only at the end of the process\n\n# METHODS\n\n[Mojo::IOLoop::ReadWriteProcess](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess) inherits all methods from [Mojo::EventEmitter](https://metacpan.org/pod/Mojo%3A%3AEventEmitter) and implements\nthe following new ones.\n\n## start()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub {\n                          print STDERR \"Boo\\n\"\n                      } )-\u003estart;\n\nStarts the process\n\n## stop()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process( execute =\u003e \"/path/to/bin\" )-\u003estart-\u003estop;\n\nStop the process. Unless you use `wait_stop()`, it will attempt to kill the process\nwithout waiting the process to finish. By defaults it send `SIGTERM` to the child.\nYou can change that by defining the internal attribute `_default_kill_signal`.\nNote, if you want to be \\*sure\\* that the process gets killed, you can enable the\n`blocking_stop` attribute, that will attempt to send `SIGKILL` after `max_kill_attempts`\nis reached.\n\n## restart()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process( execute =\u003e \"/path/to/bin\" )-\u003erestart;\n\nIt restarts the process if stopped, or if already running, it stops it first.\n\n## is\\_running()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process( execute =\u003e \"/path/to/bin\" )-\u003estart;\n    $p-\u003eis_running;\n\nBoolean, it inspect if the process is currently running or not.\n\n## exit\\_status()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process( execute =\u003e \"/path/to/bin\" )-\u003estart;\n\n    $p-\u003ewait_stop-\u003eexit_status;\n\nInspect the process exit status, it does the shifting magic, to access to the real value\ncall `_status()`.\n\n## return\\_status()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process( sub { return 42 } )-\u003estart;\n\n    my $s = $p-\u003ewait_stop-\u003ereturn_status; # 42\n\nInspect the codeblock return.\n\n## enable\\_subreaper()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process()-\u003eenable_subreaper;\n\nMark the current process (not the child) as subreaper.\nThis is used typically if you want to mark further children as subreapers inside other forks.\n\n    my $master_p = process(\n      sub {\n        my $p = shift;\n        $p-\u003eenable_subreaper;\n\n        process(sub { sleep 4; exit 1 })-\u003estart();\n        process(\n          sub {\n            sleep 4;\n            process(sub { sleep 1; })-\u003estart();\n          })-\u003estart();\n        process(sub { sleep 4; exit 0 })-\u003estart();\n        process(sub { sleep 4; die })-\u003estart();\n        my $manager\n          = process(sub { sleep 2 })-\u003esubreaper(1)-\u003estart();\n        sleep 1 for (0 .. 10);\n        $manager-\u003estop;\n        return $manager-\u003esession-\u003eall-\u003esize;\n      });\n\n    $master_p-\u003esubreaper(1);\n\n    $master_p-\u003eon(collected =\u003e sub { $status++ });\n\n    # On start we setup the current process as subreaper\n    # So it's up on us to disable it after process is done.\n    $master_p-\u003eon(stop =\u003e sub { shift()-\u003edisable_subreaper });\n    $master_p-\u003estart();\n\n## disable\\_subreaper()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process()-\u003edisable_subreaper;\n\nUnset the current process (not the child) as subreaper.\n\n## prctl()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process();\n    $p-\u003eprctl($option, $arg2, $arg3, $arg4, $arg5);\n\nInternal function to execute and wrap the prctl syscall, accepts the same arguments as prctl.\n\n## diag()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub { print \"Hello\\n\" });\n    $p-\u003eon( stop =\u003e sub { shift-\u003ediag(\"Done!\") } );\n    $p-\u003estart-\u003ewait_stop;\n\nInternal function to print information to STDERR if verbose attribute is set or either DEBUG mode enabled.\nYou can use it if you wish to display information on the process status.\n\n## to\\_ioloop()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n\n    my $p = process(sub {  print \"Hello from first process\\n\"; sleep 1 });\n\n    $p-\u003estart(); # Start and sets the handlers\n    my $stream = $p-\u003eto_ioloop; # Get the stream and demand to IOLoop\n    my $output;\n\n    # Hook on Mojo::IOLoop::Stream events\n    $stream-\u003eon(read =\u003e sub { $output .= pop;  $p-\u003eis_running ...  });\n\n    Mojo::IOLoop-\u003esingleton-\u003estart() unless Mojo::IOLoop-\u003esingleton-\u003eis_running;\n\nReturns a [Mojo::IOLoop::Stream](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AStream) object and demand the wait operation to [Mojo::IOLoop](https://metacpan.org/pod/Mojo%3A%3AIOLoop).\nIt needs `set_pipes` enabled. Default IOLoop can be overridden in `ioloop()`.\n\n## wait()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub { print \"Hello\\n\" })-\u003ewait;\n    # ... here now you can mangle $p handlers and such\n\nWaits until the process finishes, but does not performs cleanup operations (until stop is called).\n\n## wait\\_stop()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub { print \"Hello\\n\" })-\u003estart-\u003ewait_stop;\n    # $p is not running anymore, and all possible events have been granted to be emitted.\n\nWaits until the process finishes, and perform cleanup operations.\n\n## errored()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub { die \"Nooo\" })-\u003estart-\u003ewait_stop;\n    $p-\u003eerrored; # will return \"1\"\n\nReturns a boolean indicating if the process had errors or not.\n\n## write\\_pidfile()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub { die \"Nooo\" } );\n    $p-\u003epidfile(\"foobar\");\n    $p-\u003estart();\n    $p-\u003ewrite_pidfile();\n\nForces writing PID of process to specified pidfile in the attributes of the object.\nUseful only if the process have been already started, otherwise if a pidfile it's supplied\nas attribute, it will be done automatically.\n\n## write\\_stdin()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub { my $a = \u003cSTDIN\u003e; print STDERR \"Hello my name is $a\\n\"; } )-\u003estart;\n    $p-\u003ewrite_stdin(\"Larry\");\n    $p-\u003eread_stderr; # process STDERR will contain: \"Hello my name is Larry\\n\"\n\nWrite data to process STDIN.\n\n## write\\_channel()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub {\n                          my $self = shift;\n                          my $parent_output = $self-\u003echannel_out;\n                          my $parent_input  = $self-\u003echannel_in;\n\n                          while(defined(my $line = \u003c$parent_input\u003e)) {\n                            print $parent_output \"PONG\\n\" if $line =~ /PING/i;\n                          }\n                      } )-\u003estart;\n    $p-\u003ewrite_channel(\"PING\");\n    my $out = $p-\u003eread_channel;\n    # $out is PONG\n    my $child_output = $p-\u003echannel_out;\n    while(defined(my $line = \u003c$child_output\u003e)) {\n        print \"Process is replying back with $line!\\n\";\n        $p-\u003ewrite_channel(\"PING\");\n    }\n\nWrite data to process channel. Note, it's not STDIN, neither STDOUT, it's a complete separate channel\ndedicated to parent-child communication.\nIn the parent process, you can access to the same pipes (but from the opposite direction):\n\n    my $child_output = $self-\u003echannel_out;\n    my $child_input  = $self-\u003echannel_in;\n\n## read\\_stdout()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub {\n                          print \"Boo\\n\"\n                      } )-\u003estart;\n    $p-\u003eread_stdout;\n\nGets a single line from process STDOUT.\n\n## read\\_channel()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub {\n                          my $self = shift;\n                          my $parent_output = $self-\u003echannel_out;\n                          my $parent_input  = $self-\u003echannel_in;\n\n                          print $parent_output \"PONG\\n\";\n                      } )-\u003estart;\n    $p-\u003eread_channel;\n\nGets a single line from process channel.\n\n## read\\_stderr()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub {\n                          print STDERR \"Boo\\n\"\n                      } )-\u003estart;\n    $p-\u003eread_stderr;\n\nGets a single line from process STDERR.\n\n## read\\_all\\_stdout()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub {\n                          print \"Boo\\n\"\n                      } )-\u003estart;\n    $p-\u003eread_all_stdout;\n\nGets all the STDOUT output of the process.\n\n## read\\_all\\_channel()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub {\n                          shift-\u003echannel_out-\u003ewrite(\"Ping\")\n                      } )-\u003estart;\n    $p-\u003eread_all_channel;\n\nGets all the channel output of the process.\n\n## read\\_all\\_stderr()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process(sub {\n                          print STDERR \"Boo\\n\"\n                      } )-\u003estart;\n    $p-\u003eread_all_stderr;\n\nGets all the STDERR output of the process.\n\n## send\\_signal()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    use POSIX;\n    my $p = process( execute =\u003e \"/path/to/bin\" )-\u003estart;\n\n    $p-\u003esend_signal(POSIX::SIGKILL);\n\nSend a signal to the process\n\n# EXPORTS\n\n## parallel()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(parallel);\n    my $pool = parallel sub { print \"Hello\\n\" } =\u003e 5;\n    $pool-\u003estart();\n    $pool-\u003eon( stop =\u003e sub { print \"Process: \".(+shift()-\u003epid).\" finished\"; } );\n    $pool-\u003estop();\n\nReturns a [Mojo::IOLoop::ReadWriteProcess::Pool](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess%3A%3APool) object that represent a group of processes.\n\nIt accepts the same arguments as [Mojo::IOLoop::ReadWriteProcess](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess), and the last one represent the number of processes to generate.\n\n## batch()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(batch);\n    my $pool = batch;\n    $pool-\u003eadd(sub { print \"Hello\\n\" });\n    $pool-\u003eon(stop =\u003e sub { shift-\u003e_diag(\"Done!\") })-\u003estart-\u003ewait_stop;\n\nReturns a [Mojo::IOLoop::ReadWriteProcess::Pool](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess%3A%3APool) object generated from supplied arguments.\nIt accepts as input the same parameter of [Mojo::IOLoop::ReadWriteProcess::Pool](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess%3A%3APool) constructor ( see parallel() ).\n\n## process()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(process);\n    my $p = process sub { print \"Hello\\n\" };\n    $p-\u003estart()-\u003ewait_stop;\n\nor even:\n\n    process(sub { print \"Hello\\n\" })-\u003estart-\u003ewait_stop;\n\nReturns a [Mojo::IOLoop::ReadWriteProcess](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess) object that represent a process.\n\nIt accepts the same arguments as [Mojo::IOLoop::ReadWriteProcess](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess).\n\n## queue()\n\n    use Mojo::IOLoop::ReadWriteProcess qw(queue);\n    my $q = queue;\n    $q-\u003eadd(sub { return 42 } );\n    $q-\u003econsume;\n\nReturns a [Mojo::IOLoop::ReadWriteProcess::Queue](https://metacpan.org/pod/Mojo%3A%3AIOLoop%3A%3AReadWriteProcess%3A%3AQueue) object that represent a queue.\n\n# DEBUGGING\n\nYou can set the MOJO\\_EVENTEMITTER\\_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.\n\n    MOJO_EVENTEMITTER_DEBUG=1\n\nAlso, you can set MOJO\\_PROCESS\\_DEBUG environment variable to get diagnostics about the process execution.\n\n    MOJO_PROCESS_DEBUG=1\n\n# LICENSE\n\nCopyright (C) Ettore Di Giacinto.\n\nThis library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.\n\n# AUTHOR\n\nEttore Di Giacinto \u003cedigiacinto@suse.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensuse%2Fmojo-ioloop-readwriteprocess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopensuse%2Fmojo-ioloop-readwriteprocess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensuse%2Fmojo-ioloop-readwriteprocess/lists"}