Jump to content
BrainPill

how to run shell script with browser action as trigger

Recommended Posts

I have a complicated situation

I want to execute a php script that runs in the background while a browser script is used as trigger.

 

I use wamp CLI to execute a php script like this:

 

php test.php

 

 

I want to execute this script in the browser with this script

 

$outp = shell_exec("php test.php");


echo '<br>';
echo $outp;
echo '<br>';

 

It doesnt work. The page in the browser is giving no output

I can do shell_exec("whoami"), or shell_exec('dir'); So this works, but executing a script not.

 

What causes this error?

 

 

 

Share this post


Link to post
Share on other sites

space in the filename.

Share this post


Link to post
Share on other sites
14 hours ago, niche said:

space in the filename.

I tested :

shell_exec("phptest.php");

to get rid of the space.

Not sure if it is possible if there can be a space in the filename while saved?

never heared about that

 

Share this post


Link to post
Share on other sites

Do I have to set a path or so for the Command Line Interface , PHP_CLI ?

If so, how should this be done?

 

EDIT:

as there are many OS and approaches of PHP I have some additional info about my set up.

I use WAMP 3.1.9 with windows 10. PHP version 7.3.5

Edited by BrainPill

Share this post


Link to post
Share on other sites

what happens when you add a path? 

Share this post


Link to post
Share on other sites
On 1/21/2020 at 12:39 PM, niche said:

what happens when you add a path? 

I tried that. Are there specific rules I should follow? 

What actually happens when you call a php shell_exec command? Where will the command look to start something? 

Share this post


Link to post
Share on other sites
On 1/21/2020 at 12:39 PM, niche said:

what happens when you add a path? 

I tried that. Are there specific rules I should follow? 

What actually happens when you call a php shell_exec command? Where will the command look to start something? 

--------------------------------------------------------

Edit: I tried the following

 


$var = php_sapi_name();
var_dump($var);

the output is: apache2handler

In the manual of php is a number of outputs mentioned 

Quote

aolserver, apache, apache2filter, apache2handler, caudium, cgi (until PHP 5.3), cgi-fcgi, cli, cli-server, continuity, embed, fpm-fcgi, isapi, litespeed, milter, nsapi, phpdbg, phttpd, pi3web, roxen, thttpd, tux, and webjames.

https://www.php.net/manual/en/function.php-sapi-name.php

 

I dont know if this is the solution but it coudl be so does anyone know if the sapi can be set to cli or cli-server maybe?

 

Share this post


Link to post
Share on other sites

Or should I change the php.ini settings? 

I figured out I have (at least) 2 different php.ini files. One in the apache dir and 1 in the php dir

Edited by BrainPill

Share this post


Link to post
Share on other sites

If you access the php localhost FROM taskbar (wamp->php->localhost (I think)) page and look for php.ini, it will identify the used file location.

You can also add phpinfo() to a php page.

Edited by dsonesuk

Share this post


Link to post
Share on other sites

The path for my WAMP is 

$file = "drive:/wamp64/tmp/filename_with_extention";

 

Share this post


Link to post
Share on other sites

It still does not work for me. What I tried is this:

 

$output = shell_exec("A:/wamp64/test/batchscripts/hello_world.php");


echo '<br>';
echo $output;
echo '<br>';

 

Share this post


Link to post
Share on other sites

I think the issue is hello_world.php in not a command.

This works fine:

shell_exec("mkdir data5");
EDIT:

This might help - 

https://hotexamples.com/examples/-/-/shell_exec/php-shell_exec-function-examples.html

Edited by niche

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...