1

i want to see the results of shell script in a textarea but i dont know how to do that, i try like this: php file:

<?php
function JTSstat(){
exec('sh JTSstat.sh', $output);

}
?>

...

<form action="5ondimba.php" method="post">
<input type="submit" value="STATUS" onclick="JTSstat()">
</form>
...

<textarea style="display:table-cell;width:100%;resize:none;"rows="7"readonly><?php echo $output ?></textarea>

but obviusly i receve this error:

PHP Notice:  Undefined variable

EDIT:i know why it gives me this error, but i dont know how to do what i need.

what i need to do to do it? Thanks!

Flynns 82
  • 25
  • 1
  • 1
  • 7

1 Answers1

2

You can't call a php function this way. You need to submit the form first. Then find the output. To hide undefined index initialize the variable with a null string. Also make sure you are following one of the two.

  • both php and html in one page (5ondimba.php)

or

  • Include your html page after php script and when you html form action point to 5ondimba.php (hoping that your php is in 5ondimba.php.

Learn more about undefined index here

<?php
$output = '' ; //Initialize variable with default value.
if( isset($_POST['submit']) ) {
//Is form submited, call the exec.
exec('sh JTSstat.sh', $output);
}

//var_dump($output) ;
?>

...

<form action="5ondimba.php" method="post">
<input type="submit" value="STATUS" name="submit" > <!-- Removed function call -->
</form>
...

<textarea style="display:table-cell;width:100%;resize:none;"rows="7"readonly><?php print_r($output) ?></textarea>
nithinTa
  • 1,632
  • 2
  • 16
  • 32
  • action need be on same page. mention it. It may possible that `5ondimba.php` is second page name?. BTW +1 – Alive to die - Anant Nov 06 '17 at 04:40
  • i tryed like this but not work 100%, i see only the text "Array" on the textarea, instead i should see "Array ( [0] => JTS3ServerMod is running! ) " – Flynns 82 Nov 06 '17 at 04:41
  • @AlivetoDie 5ondimba.php its the only one page, all the code that i have write in this thread is in this file – Flynns 82 Nov 06 '17 at 04:42
  • @AlivetoDie thank you for pointig it. – nithinTa Nov 06 '17 at 04:51
  • @Flynns82 exec returns array, so when casting with echo it will just print array. Try print_r($output) instead to see the array values or you can merge the result array using implode http://php.net/manual/en/function.implode.php . – nithinTa Nov 06 '17 at 05:02
  • Perfect, with print_r all works! thanks so much!! – Flynns 82 Nov 06 '17 at 12:11