Creates a new process for the execution of a command.

@param string $cmd The command to execute.
@param string $cwd The current working directory.

@return \Symfony\Component\Process\Process The created process.
508604
protected function createProcess(string $cmd, string $cwd): Process
    {
        $process = $this->processFactory->getProcess(
            $cmd,
            $cwd,
            $this->discoverSystemEnvironment()
        );
        $process->setTimeout(null);

        return $process;
    }
1343464
public function execute($cmd, $data)
    {
        // Use pipes for STDIN, STDOUT, and STDERR
        $descr = array(
          0 => array(
            'pipe',
            'r'
          ) ,
          1 => array(
            'pipe',
            'w'
          ) ,
          2 => array(
            'pipe',
            'w'
          )
        );
        $pipes = [];

        // Start process, telling it to use STDIN for input and STDOUT for output.
        $cmd = escapeshellcmd($cmd);
        $process = proc_open($cmd, $descr, $pipes);

        // Get the data into pipe only if data is resource
        if (gettype($data) == "resource") {
            // Stream input to STDIN
            while (!feof($data)) {
                fwrite($pipes[0], fread($data, 1024));
            }

            // Close STDIN and the source data.
            fclose($pipes[0]);
            fclose($data);
        }

        // Wait for process to finish while reading STDOUT to a temp stream.
        // Otherwise the process can block indefinitely if STODUT gets bigger
        // than 4kb.
        $this->output = fopen("php://temp", 'w+');
        $exit_code = null;
        while ($exit_code === null) {
            $status = proc_get_status($process);
            if ($status['running'] === false) {
                $exit_code = $status['exitcode'];
            }

            $chunk = stream_get_contents($pipes[1]);
            if ($chunk !== false) {
                fwrite($this->output, $chunk);
            }
        }

        // Close STDOUT
        fclose($pipes[1]);

        // On error, extract message from STDERR and throw an exception.
        if ($exit_code != 0) {
            $msg = stream_get_contents($pipes[2]);
            $this->cleanup($pipes, $this->output, $process);
            if ($this->log) {
                $this->log->error('Process exited with non-zero code.', [
                  'exit_code' => $exit_code,
                  'stderr' => $msg,
                ]);
            }
            throw new \RuntimeException($msg, 500);
        }

        // Return a function that streams the output.
        return function () use ($pipes, $process) {
            rewind($this->output);
            while (!feof($this->output)) {
                echo fread($this->output, 1024);
                ob_flush();
                flush();
            }
            $this->cleanup($pipes, $this->output, $process);
        };
    }
776028
function cmd_CWD($fd, $cmd)
    {
        $user = $this->getUser($fd);
        if (($dir = $this->setUserDir($user, $cmd[1])) != false)
        {
            $this->send($fd, "250 OK. Current directory is " . $dir);
        }
        else
        {
            $this->send($fd, "550 Can't change directory to " . $cmd[1] . ": No such file or directory");
        }
    }
911038
protected function _pipeline($cmd = null)
    {
        if (!isset($this->_temp['fetchob'])) {
            $this->_temp['fetchob'] = new Horde_Imap_Client_Fetch_Results(
                $this->_fetchDataClass,
                Horde_Imap_Client_Fetch_Results::SEQUENCE
            );
        }

        $ob = new Horde_Imap_Client_Interaction_Pipeline(
            clone $this->_temp['fetchob']
        );

        if (!is_null($cmd)) {
            $ob->add($cmd);
        }

        return $ob;
    }
760594
function cmd_MKD($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $path = $this->getAbsDir($user).$cmd[1];

        if (!is_dir(dirname($path)))
        {
            $this->send($fd, "550 Can't create directory: No such file or directory");
        }
        elseif(file_exists($path))
        {
            $this->send($fd, "550 Can't create directory: File exists");
        }
        else
        {
            if (mkdir($path))
            {
                $this->send($fd, "257 \"" . $cmd[1] . "\" : The directory was successfully created");
            }
            else
            {
                $this->send($fd, "550 Can't create directory: Permission denied");
            }
        }
    }
1064476
public function executeCommand($cmd, \Closure $closure = null, Process $process = null)
    {
        try {
            $cmd = $this->php.' '.$this->console.' '.$cmd;
            if (null === $process) {
                $process =  new Process($cmd);
            } else {
                $process->setCommandLine($cmd);
            }

            return $process->run($closure);
        } catch (\Exception $e) {
            return false;
        }
    }
1027618
public function executeCommandInProcess($cmd, $timeout = null){
        Context::get('output')->write("<comment>$cmd</comment>\n\n");
        $process = new Process($cmd);

        if ($timeout !== null) {
            $process->setTimeout($timeout);
        }

        $process->run(function ($type, $buffer) {
            Context::get('output')->write($buffer);
        });
        return $process;
    }
217445
def execute(cmd, cwd=None):
    
    try:
        lines = subprocess \
            .check_output(cmd, cwd=cwd, stderr=DEVNULL) \
            .splitlines()
    except subprocess.CalledProcessError:
        return None
    else:
        if lines:
            return decode(lines[0].strip())
        else:
            return None
114324
public function spawn($cmd, $options = array(), $start = true)
    {
        // Generate guid
        $guid = uniqid();
        // Get create directory
        $dir = !empty($options['dir']) ? $options['dir'] : sys_get_temp_dir();
        // Events name
        $types = array('stdin', 'stdout', 'stderr');
        // Files to descriptor
        $files = array();
        // Self
        $self = $this;

        // Define the stdin stdout and stderr files
        foreach ($types as $type) {
            $files[] = $file = $dir . '/' . $guid . '.' . $type;
            posix_mkfifo($file, 0600);
        }

        $child = $this->parallel(function ($process) use ($cmd, $files) {
            $pipes = array();

            // Make file descriptors for proc_open()
            $fd = array();
            foreach ($files as $i => $file) {
                $fd[] = array('file', $file, $i > 0 ? 'w' : 'r');
            }

            // Open pipe to run process
            $resource = proc_open($cmd, $fd, $pipes);

            if (!is_resource($resource)) {
                throw new \RuntimeException('Can not run "' . $cmd . '" using pipe open');
            }

            // Close all pipes
            foreach ($pipes as $pipe) {
                fclose($pipe);
            }

            proc_close($resource);
            exit;
        }, $options, $start);

        $child->on('fork', function () use (&$files, $child, $types, $self) {
            // Make file descriptor
            $pipes = array();
            foreach ($files as $i => $file) {
                $pipes[] = fopen($file, $i > 0 ? 'r' : 'w');
            }

            // Create tick process callback
            $tick = function () use ($pipes, $child, $types) {
                $readers = $pipes;

                // Select the streams
                if (empty($readers) || stream_select($readers, $null, $null, 0) <= 0) return;

                // Check which reader selected and emit event
                foreach ($readers as $reader) {
                    if (!is_resource($reader)) continue;
                    $index = array_search($reader, $pipes);
                    while (!feof($reader)) {
                        $child->emit($types[$index], fgets($reader));
                    }
                }
            };

            // Register tick function to check streams
            $self->on('tick', $tick);

            // Remove file when exit
            $child->on('exit', function () use ($tick, $self, &$files, &$pipes) {
                $self->removeListener('tick', $tick);
                foreach ($files as $file) {
                    unlink($file);
                }
                $files = $pipes = array();
            });
        });

        return $child;
    }
384733
public function run($cmd)
    {
        $cmd = "{$this->phpBinaryPath} {$this->file} $cmd";
        $cmd = $this->isWindows() === true
            ? $cmd = "start /b {$cmd}"
            : $cmd = "{$cmd} > /dev/null 2>&1 &";

        pclose(popen($cmd, 'r'));

        return true;
    }
285405
public function execute($command, $cwd = null)
    {
        if (strpos($command, '<') === 0) {
            return array(true, trim($command, '< '));
        }
        
        $processExecutor = $this->getProcessExecutor();

        $logger = $this->logger;

        $output = '';
        
        $outputHandler = function ($type, $data) use ($logger, &$output) {
            $output .= $data;
            
            $logger->writeVerbose('comment', trim($data));
        };
        
        if ($this->logger->getOutputInstance()->isVerbose()) {
            $this->logger->writeIndentation();
        }
        
        $result = $processExecutor->execute($command, $outputHandler, $cwd);

        return array($result === 0, $output);
    }
513889
public function pipeOutputTo(Command $cmd) : void
    {
        if (!$this->canPipe()) {
            throw new RuntimeException('Can\'t pipe output');
        }
        $this->pipeline[] = $cmd;
    }
1310231
protected function _exec($cmd, $input = "")
        {
            $result = array(
                'stdout' => '',
                'stderr' => '',
                'return' => ''
            );

            $proc = proc_open(
                $cmd,
                array(
                    0 => array(
                        'pipe',
                        'r'
                    ),
                    1 => array(
                        'pipe',
                        'w'
                    ),
                    2 => array(
                        'pipe',
                        'w'
                    )
                ),
                $pipes
            );
            fwrite($pipes[0], $input);
            fclose($pipes[0]);

            $result['stdout'] = stream_get_contents($pipes[1]);
            fclose($pipes[1]);

            $result['stderr'] = stream_get_contents($pipes[2]);
            fclose($pipes[2]);

            $result['return'] = proc_close($proc);

            return $result;
        }
576647
private function runCommand(Process $process)
    {
        $output = $this->output;

        /** @type DebugFormatterHelper $debugFormatter */
        $debugFormatter = $this->getHelperSet()->get('debug_formatter');
        if (null !== $dispatcher = $this->getEventDispatcher()) {
            $event = new PreExecuteEvent($this, $process);
            $dispatcher->dispatch(Event::PRE_EXECUTE, $event);

            if ($event->isPropagationStopped()) {
                $output->writeln(
                    ['', sprintf('    <info>[%s]</info> - <comment>Stopped</comment>', $this->getName()), '']
                );

                return true;
            }
        }

        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) {
            $output->writeln('        // '.$process->getCommandLine());
        }

        if ($this->getParameter('dry_run')) {
            return true;
        }

        if ($this->hasParameter('cwd')) {
            $process->setWorkingDirectory($this->getParameter('cwd'));
        }

        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
            $output->writeln(
                sprintf(
                    '        // Setting timeout for %d seconds.',
                    $this->getParameter('timeout')
                )
            );
        }
        $process->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null);

        if ($this->hasParameter('output')) {
            $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
            $stream = fopen($this->getParameter('output'), $append);
            $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
        }

        $output->writeln(
            $debugFormatter->start(
                spl_object_hash($process),
                $process->getCommandLine()
            )
        );

        $process->start();

        return $process;
    }
83617
public function exec($command, $runDir = null, Closure $callback = null, $timeout = null)
    {
        $process = new Process($command, $runDir);

        $process->setTimeout($timeout);

        $this->startedAt = Carbon::now();

        $process->run($callback);

        $this->endedAt = Carbon::now();

        return $process;
    }
143811
public function cmd($cmd)
    {
        $cmd = ltrim($cmd);
        if (substr($cmd, 0, 1) === '@') {
            return $this->resolve(array_merge(array('tasks'), explode('.', substr($cmd, 1))));
        } else {
            $this->exec($cmd);
            return null;
        }
    }
258226
protected function executeCmd($command)
    {
        $process = new $this->processClass($command);
        $process->run();

        if (false === $process->isSuccessful() && strlen($process->getErrorOutput()) > 0) {
            throw new \RuntimeException($process->getErrorOutput());
        }

        return $process->getOutput();
    }