{
    "mode": "perldoc",
    "parameter": "IPC::Open3",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/IPC%3A%3AOpen3/json",
    "generated": "2026-06-13T18:24:41Z",
    "synopsis": "use Symbol 'gensym'; # vivify a separate handle for STDERR\nmy $pid = open3(my $chldin, my $chldout, my $chlderr = gensym,\n'some', 'cmd', 'and', 'args');\n# or pass the command through the shell\nmy $pid = open3(my $chldin, my $chldout, my $chlderr = gensym,\n'some cmd and args');\n# read from parent STDIN\n# send STDOUT and STDERR to already open handle\nopen my $outfile, '>>', 'output.txt' or die \"open failed: $!\";\nmy $pid = open3('<&STDIN', $outfile, undef,\n'some', 'cmd', 'and', 'args');\n# write to parent STDOUT and STDERR\nmy $pid = open3(my $chldin, '>&STDOUT', '>&STDERR',\n'some', 'cmd', 'and', 'args');\n# reap zombie and retrieve exit status\nwaitpid( $pid, 0 );\nmy $childexitstatus = $? >> 8;",
    "sections": {
        "NAME": {
            "content": "IPC::Open3 - open a process for reading, writing, and error handling using open3()\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Symbol 'gensym'; # vivify a separate handle for STDERR\nmy $pid = open3(my $chldin, my $chldout, my $chlderr = gensym,\n'some', 'cmd', 'and', 'args');\n# or pass the command through the shell\nmy $pid = open3(my $chldin, my $chldout, my $chlderr = gensym,\n'some cmd and args');\n\n# read from parent STDIN\n# send STDOUT and STDERR to already open handle\nopen my $outfile, '>>', 'output.txt' or die \"open failed: $!\";\nmy $pid = open3('<&STDIN', $outfile, undef,\n'some', 'cmd', 'and', 'args');\n\n# write to parent STDOUT and STDERR\nmy $pid = open3(my $chldin, '>&STDOUT', '>&STDERR',\n'some', 'cmd', 'and', 'args');\n\n# reap zombie and retrieve exit status\nwaitpid( $pid, 0 );\nmy $childexitstatus = $? >> 8;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Extremely similar to open2(), open3() spawns the given command and connects $chldout for\nreading from the child, $chldin for writing to the child, and $chlderr for errors. If\n$chlderr is false, or the same file descriptor as $chldout, then STDOUT and STDERR of the\nchild are on the same filehandle. This means that an autovivified lexical cannot be used for the\nSTDERR filehandle, but gensym from Symbol can be used to vivify a new glob reference, see\n\"SYNOPSIS\". The $chldin will have autoflush turned on.\n\nIf $chldin begins with \"<&\", then $chldin will be closed in the parent, and the child will\nread from it directly. If $chldout or $chlderr begins with \">&\", then the child will send\noutput directly to that filehandle. In both cases, there will be a dup(2) instead of a pipe(2)\nmade.\n\nIf either reader or writer is the empty string or undefined, this will be replaced by an\nautogenerated filehandle. If so, you must pass a valid lvalue in the parameter slot so it can be\noverwritten in the caller, or an exception will be raised.\n\nThe filehandles may also be integers, in which case they are understood as file descriptors.\n",
            "subsections": [
                {
                    "name": "open3",
                    "content": "raises an exception matching \"/^open3:/\". However, \"exec\" failures in the child (such as no such\nfile or permission denied), are just reported to $chlderr under Windows and OS/2, as it is not\npossible to trap them.\n\nIf the child process dies for any reason, the next write to $chldin is likely to generate a\nSIGPIPE in the parent, which is fatal by default. So you may wish to handle this signal.\n\nNote if you specify \"-\" as the command, in an analogous fashion to \"open(my $fh, \"-|\")\" the\nchild process will just be the forked Perl process rather than an external command. This feature\nisn't yet supported on Win32 platforms.\n"
                },
                {
                    "name": "open3",
                    "content": "where it's acceptable to let the operating system take care of this, you need to do this\nyourself. This is normally as simple as calling \"waitpid $pid, 0\" when you're done with the\nprocess. Failing to do this can result in an accumulation of defunct or \"zombie\" processes. See\n\"waitpid\" in perlfunc for more information.\n\nIf you try to read from the child's stdout writer and their stderr writer, you'll have problems\nwith blocking, which means you'll want to use select() or IO::Select, which means you'd best use"
                },
                {
                    "name": "sysread",
                    "content": "This is very dangerous, as you may block forever. It assumes it's going to talk to something\nlike bc(1), both writing to it and reading from it. This is presumably safe because you \"know\"\nthat commands like bc(1) will read a line at a time and output a line at a time. Programs like"
                },
                {
                    "name": "sort",
                    "content": "The big problem with this approach is that if you don't have control over source code being run\nin the child process, you can't control what it does with pipe buffering. Thus you can't just\nopen a pipe to \"cat -v\" and continually read and write a line from it.\n\nSee Also\nIPC::Open2\nLike Open3 but without STDERR capture.\n\nIPC::Run\nThis is a CPAN module that has better error handling and more facilities than Open3.\n"
                }
            ]
        },
        "WARNING": {
            "content": "The order of arguments differs from that of open2().\n",
            "subsections": []
        }
    },
    "summary": "IPC::Open3 - open a process for reading, writing, and error handling using open3()",
    "flags": [],
    "examples": [],
    "see_also": []
}