0

How do I clear the terminal and show the output of my script after a blank terminal.

This is the top of my script:

#!/usr/bin/env php <?php require_once("setting/phpmailer/PHPMailerAutoload.php"); include('setting/mks.settings.php');

its the different question from my last, my last question is how to make my tag working, but in this question im asking how to make bash command clear working on my php bash @mario, thx The way I run this script as the bash script ./myfile

I want to make like the clear command on bash, but I don't know how to do so, when I put clear it just print out clear without clearing the terminal.

  • 1
    This may sound silly, but have you tried executing the command (`exec('clear');`)? – rickdenhaan Mar 03 '19 at 21:22
  • i have tried adding it on my php bash script, it just print out (exec('clear');) EDIT : have tried it, doesnt work, just came usually but not cleared – Cahya Darma Wijaya Mar 03 '19 at 21:30
  • 1
    Not reproducible from the sample code provided. – mario Mar 03 '19 at 21:33
  • 1
    Just ran a test and `exec('clear');` does not work. However, this following taken from @mario's duplicate does work on my machine: `echo "\033[2J\033[1;1H";` – rickdenhaan Mar 03 '19 at 21:40
  • @rickdenhaan I think `clear` would also work. But it might need something like `passthru("clear -T xterm 2>&1");` because it also just returns the ANSI sequence instead of manipulating the terminal directly. – mario Mar 03 '19 at 21:47
  • You could probably do it with PHPSecLib and SSH with interactive shell. The reason it probably doesn't work is each `exec` or shell call in PHP is kin to opening its own terminal, so you cant call multiple commands against the same terminal. http://phpseclib.sourceforge.net/ssh/2.0/examples.html `$ssh->exec('clear')` then `$ssh->exec('some other command')` etc.. So there is little point calling just `exec('clear')` because it just opens a new terminal and calls clear against that. Or at least that is how I understand it. – ArtisticPhoenix Mar 03 '19 at 22:03
  • I just realized you want to do it from inside the shell script, not from the PHP file executing the shell scrip. ... anyway.... lol the same thing applies to running `exec('clear')` from inside the shell script, it opens a new terminal and clears it, which has no effect on the current terminal its running the shell script inside of. – ArtisticPhoenix Mar 03 '19 at 22:08

0 Answers0