PHP @exec fails

It drives me crazy. I am trying to execute a command line operator in a windows window for my PHP web application. It works on Windows XP, IIS5.1. The web application is working fine, but I cannot get @exec () to work with a specific contact variable. My command construct looks like this:

$cmd = ($config->svn." cat ".$this->repConfig->svnParams().quote($path).' -r '.$rev.' > '.quote($filename));

This command does not work as indicated above when it generates the following line:

svn --non-interactive --config-dir /tmp cat "file:///c:/temp/test/acccount/dbo_sproctest.sql" -r 1 > "C:\Inetpub\sites\websvn\temp\wsv5B45.tmp"

If I copy / paste this into my own command line, it works fine.

If I hardcode the same path rather than adding it with a variable, it works! I tried with and without quotes around the file name. I tried without quotes throughout the team. I tried other directories. I tried passing the output parameter to exec () and it returns empty (Array ()). I tried to redirect the output of the command error stream to a file, and this error output file is never created.

The only thing I can understand is that exec () fails. What am I doing wrong here? If I hardcode the file path using the same structure and file name, it works fine. If I do not, it is not.

It is possible that slashes () in the file path are not escaped properly, but when I do this manually with single quotes, they are not considered escape sequences

UPDATE:

I took @off exec and still see no errors.

SVN, . , SVN , cat.

2: RE: Kieth

exec, :

exec($cmd);

exec($cmd, $out);

php.ini safe_mode = 0.

error_reporting (E_ALL);

( print_r) exec,

echo ( print_r) exec var, arr

3

escapeshellcmd, escapeshellarg ( ).

,

tempnam("temp", "wbsn");

, , , tempname, , , , , . , , .

+3
9

@exec , @ PHP.

+23

, , Windows, Linux, PHP exec(). , , (nconvert), , .

2>&1

, . , nconvert .

+3

, PATH php script . @ , .

, SVN.

+2

, @ , , :

error_reporting(E_ALL);

, php.ini .

, , exec()? , script ? , exec(), , ?

+1

, , .

PHP : escapeshellcmd escapeshellarg.

, escapeshellcmd $cmd, .

+1

echo exec ( "dir" ) - , , exec() ?

+1

, , , , .

:

$tmp = tempnam("./", "wbsn");
$filename = dirname($tmp).'\\temp\\'.basename($tmp);

, , , , ( diff, tempnam()).

$tmp = tempnam("temp", "wbsn");

, , :

$tmp = tempnam("temp", "wbsn");
$filename = dirname($tmp).'\\'.basename($tmp);

3 , , , , exec. , .

() , , ( , , ). dirname() 3 . , , - .

+1

- "" . , - .

- . , , , , , . , - , , .

+1

My advice would be to switch from WIN, IIS to linux, but as an alternative, you can try the following:

function exec_alt($cmd) {
    exec($cmd, $output);
    if (!$output) {
        /**
         * FIXME: for some reason exec() returns empty output array @mine, machine.
         *        Somehow proc_open() approach (below) works, but doesn't work at
         *        test machines - same empty output with both pipes and temporary
         *        files (not we bypass shell wrapper). So use it as a fallback.
         */
        $output = array();
        $handle = proc_open($cmd, array(1 => array('pipe', 'w')), $pipes, null, null, array('bypass_shell' => true));
        if (is_resource($handle)) {
            $output = explode("\n", stream_get_contents($pipes[1]));
            fclose($pipes[1]);
            proc_close($handle);
        }
    }
    return $output; }
0
source

Source: https://habr.com/ru/post/1705876/


All Articles