Quantcast
Channel: Howto pass a mixed string from php through a pipe to a bash script - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Howto pass a mixed string from php through a pipe to a bash script

$
0
0

I'm searching for a possibility to send a mixed PHP multline string with the help of proc_open (exec, passthru or whatever) via a pipe to a bash script. Finally, within this script I want to grab the mixed multiline string and store it into a variable.

PHP:

// static way
$some_multiline_string = 'some $%§%& mixed &/(/( 
content 
with newlines';

// dynamic way:
// the mixed content is coming from the database
// so actually it is not initialized like in the previous lines, but more like this:
$some_multiline_string = $db_result['some_multiline_string'];

// escaping
$some_multiline_string = escapeshellargs($some_multiline_string);

// execution
$process = proc_open("printf $some_multiline_string | some_script.sh args");
...

Bash:

#!/bin/bash
mixed_multiline_string=$(</dev/stdin)
echo -e "$mixed_multiline_string"
...

How to escape the mixed content properly before using it within the command? I've tried already escapeshellargs and escapeshellcmd, but either there is an unescaped charackter, which is stopping the process or it's working but is taking too much time (1.5 min) for processing.

Here is a link to an example mixed content string: http://playmobox.com/js/test.txt

Thanks a lot!


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images