D
D
Dmitry2015-10-02 11:44:08
PHP
Dmitry, 2015-10-02 11:44:08

How to execute shell using php?

Hello!
Here is a command that works fine with ssh:

curl https://sandbox.zamzar.com/v1/files/9364488/content \
 -u f9b: \
 -L \
 -O \
 -J

I do it with the line:
$output = shell_exec('curl https://sandbox.zamzar.com/v1/files/9364488/content \ -u f9bddee74f393cf0f8a316771b0041fad5ca0f6a: \ -L \ -O \ -J');

Nothing happens!
How to do it with php?
--------------------
I solved this problem as it turned out to be enabled on the server - open_basedir. As a result, curl gave an error: CURLOPT_FOLLOWLOCATION!
Thank you all and help!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Valery Ryaboshapko, 2015-10-02
@muldy

It's about backslashes. The backslash followed by a line break is ignored, so you can split the command over multiple lines. When you write the command on one line, the backslashes become independent arguments that curl doesn't know what to do with and throws an error. The error is thrown on stderr, which is ignored by shell_exec, so you don't see anything. That is, to execute a command, you need to either return line breaks or remove slashes.
Well, a legitimate question. Why do you need to pull curl through shell_exec if it can be pulled using PHP itself?

6
65536, 2015-10-02
@65536

shell_exec

C
Cat Anton, 2015-10-02
@27cm

`curl https://sandbox.zamzar.com/v1/files/9364488/content ...`

php.net/manual/en/language.operators.execution.php

V
Vladimir Luchaninov, 2015-10-02
@how

curl is not a global command. this is an executable file that is somewhere, for example, in /usr/bin/curl. it is better to write the full path, because the PATH variable may be set in the shell, but in php it may not be

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question