Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Oh, my girlfriend really likes it when I launch php scripts! There's something special about them, she says ...

Thus, I coded this script to run throught the CLI (Command Line Interface) - so it's running locally, not on a web server.

It launches just fine through right click > open > run in terminal but closes right after execution. **Is there a way to keep the terminal window open?

Of course I can launch it through a terminal window - which would stay open - but I'm looking for a one click action. With bash scripts I use $SHELL but that didn't work (see code below).

So far, the only thing I came up with is sleep(10); which gives me 10 seconds for my girl to check the output. I'd rather close the terminal window manually, though.

#!/usr/bin/php -q
<?php

    echo "Hello World \n";

    # wait before closing terminal window
    sleep(10);

    # the following line doesn't work
    $SHELL;

?>

(PHP 5.4.6-1ubuntu1.2 (cli) (built: Mar 11 2013 14:57:54) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies )

share|improve this question
    
possible duplicate of How to run a script without closing the terminal? –  bodhi.zazen Mar 29 '13 at 17:34
1  
The question is not a duplicate. The link provides a solution for bash scripts. In the above case it is a php script ... adding $SHELL doesn't work. –  somethis Mar 31 '13 at 10:45
2  
You are mixing bash and php code. The correct way would be system("\$SHELL");. –  Salem Mar 31 '13 at 12:49
    
That worked ... Salem, if you post this as an official answer I can mark it of as "accepted answer" to give you credit. –  somethis Apr 9 '13 at 12:43
add comment

1 Answer

up vote 1 down vote accepted

As Salem said in this comment, you are mixing bash and php code. You can use shell_exec php function to prevent this:

#!/usr/bin/php -q
<?php

    echo "Hello World \n";

    # prevent to close terminal using php
    shell_exec('$SHELL');

?>

string shell_exec ( string $cmd ) — Execute command via shell and return the complete output as a string.

shell_exec

share|improve this answer
    
Thanks for leading this to an officially answered question :) –  somethis Jul 1 '13 at 21:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.