S
S
Sergey Pugovkin2018-03-27 15:27:08
PHP
Sergey Pugovkin, 2018-03-27 15:27:08

Why doesn't exec output anything, although there is output through the command line?

<?php

$returnStrings = [];
$returnCode = 0;
$e = exec('cd /tmp && curl --connect-timeout 10 --max-time 10 --raw --fail --remote-name http://site.ru/123.png', $returnStrings, $returnCode);

var_dump($e);
var_dump($returnStrings);
var_dump($returnCode);

Why are both $e and $returnStrings empty? Although the same command typed in the shell (putty), i.e.:
cd /tmp && curl --connect-timeout 10 --max-time 10 --raw --fail --remote-name http://site.ru/123.png

displays everything as it should: both the progress of curl and its error message (HTTP 503) with code 22.
PS Only $returnCode is not empty (== 22 in my example).
PPS I suspect that the point is that there is more than one command (but it's not clear how this interferes with php), but then how can curl specify the root folder to save the file?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Skobkin, 2018-03-27
@Driver86

how then curl'u specify the root folder to save the file?

You cddon't need it here at all.
$ curl --help | grep -i "\-o,"
 -o, --output <file> Write to file instead of stdout
 -O, --remote-name   Write output to a file named as the remote file

R
Roman, 2018-03-27
@myjcom

Do you read manuals?
php.net/manual/en/function.exec.php
;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question