Black
Black

Reputation: 20322

Execute PHP script in console in foreground

I have a script from where i try to call another script by using shell_exec():

test.php

$webroot = getcwd();
shell_exec("php $webroot/myscript.php");

myscript.php

<?php
echo "hello";

I want myscript.php to open in a console. Is this possible?

Upvotes: 2

Views: 825

Answers (2)

georoot
georoot

Reputation: 3617

I think what you mean is to run the script in GTK terminal . What you can do is something like this

$webroot = getcwd();
shell_exec("xterm -hold -e 'php $webroot/myscript.php'");

this will pop open a terminal and hold it until the user closes the same. This is for linux only.

Upvotes: 2

jekaby
jekaby

Reputation: 403

You can. Your example is working.

You can look output from shell_exec in test.php:

$webroot = getcwd();
$output = shell_exec("php $webroot/myscript.php");
echo $output;

Upvotes: 0

Related Questions