This question already has answers here:
Php exec command not working on Windows, works on command line
(3 answers)
Closed 6 years ago.
When I execute the code below in command line it runs fine:
C:\Users\Shraddha\book ticket\ex1 scrapy crawl bookmyshow
However it doesn't execute in PHP using exec():
exec("C:\Users\Shraddha\book ticket\ex1 scrapy crawl bookmyshow");
You need to escape the blank characters in the path, otherwise they are interpreted as separator between multiple arguments. Also it is much safer to use the forward slash as folder separator as it is used in unixoid systems and the internet in general:
exec("C:/Users/Shraddha/book\ ticket/ex1\ scrapy\ crawl\ bookmyshow");
If you insist on MS-Windows style separators, then you have to escape them too:
exec("C:\\Users\\Shraddha\\book\ ticket\\ex1\ scrapy\ crawl\ bookmyshow");
Also you may prefer to use shell_exec() here to have a well defined and initialized environment for your command to be executed in.
Related
This question already has answers here:
How can I execute PHP code from the command line?
(6 answers)
Closed 2 years ago.
When I run PHP in my console (any cli application) and I sending a command like below, it not returned anything!
echo 'Hi!';
Is there any way to run PHP commands directly in console or just we can run a .php file?
Note: My environment variables and path is OK.
You may use PHP's interactive shell
php -a
echo 'Hi!';
This question already has an answer here:
Convert multiple SFTP command lines to a single line command line
(1 answer)
Closed 4 years ago.
Is it possible to use SFTP linux command, using php exec() or system() function?
I try this:
exec('sftp '.$user.'#'.$server.' && '.$pass.' && get '.$path1.' '.$path2.');
but it doesnt work. Guess because of login at least)
Also tried to split execs, still its useless:
exec('sftp root#'.$server);
exec($pass);
exec('get '.$path1.' '.$path2);
maybe there is any inline command or another syntaxis for this?
And yes, i want to use SFTP, no i dont wanna use libraries.
Also if there is some way to make it work with special bash or etc file, that i can run with exec() it would be nice too.
The solution is:
system('sshpass -p '.$pass.' sftp -o StrictHostKeyChecking=no root#'.$server.':'.$path.' '.$path, $D);
This question already has an answer here:
exec(): quoting full command in Windows
(1 answer)
Closed 9 years ago.
I am trying to use the exec command from PHP in an XAMPP environment on Windows.
When I use a simple command line and type
"c:\Program Files (x86)\whatever directory\sometool.exe" "c:\temp\test.dat"
everything works perfectly.
Then I use exec command of PHP like so:
<?php
exec('"c:\Program Files (x86)\whatever directory\sometool.exe" c:\temp\test.dat');
?>
it also works.
But when I include the quotes the tool seems to not get the parameter. That means
<?php
exec('"c:\Program Files (x86)\whatever directory\sometool.exe" "c:\temp\test.dat"');
?>
does not work. I have tried escaping and everything. I cannot find a solution. But I need quotes here in order to enable paths with spaces in the name. Can you point me into the right direction?
Save your path as a variable.. then exec that. Wrap the path in single quotes like below.
$cmd = '"C:\my path with spaces\targetapp.exe" C:\mypathnospaces\targetfile.xxx';
OR - try this fix for spaces in everything, trying to use escape character on the backslash, this is UNTESTED, let me know if it works or not.
$cmd = '"C:\my path with spaces\targetapp.exe" C:\\my other path with spaces\\targetfile.xxx';
exec($cmd)
Another solution would be to add the actual PATH to your windows environment, so that you do not need to call the path at all.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
php shell_exec() vs exec()
How do I run a linux command from a PHP script? I'm running Linux Debian and PHP5. I want to be able to issue a wget command to the console.
An example of what I'm looking for is something like this:
phpFunction ("wget http://www.example.com/image.jpg /folder");
echo "done";
Also would I be able to echo the output of that function?
Use exec to run any command. Be careful not to exec any user input though, as it can severely compromise your server.
Also, note that most shared servers block off the exec function so you won't be able to use it.
Finally, as a shorthand, you can wrap the command you want to exec in backticks.
You can do what you want with the following code :
system(command);
See http://php.net/system
You can execute linux commands within a php script - all you have to do is put the command line in brackits (`).
And also concentrate on exec() , this and shell_exec() ..
you can use
exec
shell_exec
http://php.net/manual/en/function.shell-exec.php
This question already has an answer here:
Closed 12 years ago.
Possible Duplicate:
Start local PHP script w/ local Python script
How do you execute a php file and then view the output of it?
os.system("php ./index.php")
Does not work only returns 0
What you need is the os.popen function. It runs the command and returns the stdout pipe for that commands output. You can also capture the stdin, stderr by using os.popen2, popen3
import os
outp = os.popen('php ./index.php')
text = outp.read() # this will block until php finishes
# and returns with all output in text
print text
If you're working under Windows, you can use os.startfile().