You are not logged in.

#1 2021-10-26 20:47:49

Middle Office
Registered: 2015-09-29
Posts: 2,399

html textarea to php to bash script and back again?

I haven't done any php in decades now. What I'am trying to do is:

- User gets a html textarea input form (multiline)
- This gets send to php script that shall send each line to bash script (as separated parameters)

Post is populated into array

$arr = array_filter(explode("\r\n", $_POST['input']));

which seems to populate array correctly based on line breaks. Then I try to send this to the bash script

echo "<pre>".shell_exec('/home/b/bin/script '.join('\r\n',$arr)) ."</pre>";

which doesn't work correctly (breaks in spaces).
So the question would be, how to join/implode/quote/whatever to send all parameters to bash script at once?

p.s. The easy way (for each loop) is working as expected (but it is not what I want)

   foreach ($arr as &$value) {
        echo "<pre>".shell_exec("/home/b/bin/script '$value' 2>&1")."</pre>";

Last edited by brontosaurusrex (2021-10-26 21:02:48)


Board footer

Powered by FluxBB