Newbie: Printing from Perl into Bash?
Question #1: I need to send a stream of text that includes a variety of end of line characters and probably include special characters that might trip up Bash when I least expect it. The string goes FROM Perl to Bash.
This request is further complicated by the scenario. The Perl (Qpsmtpd) runs as a very low privilege user and Qpsmtpd complains if I try to use system() or back ticks. Various Perl IO modules did not work either.
I understand passing a string from Perl to Bash is not optimal, but is it possible?
Question #2: Once the output passes to the bash script, is there an elegant way to pass options as well as the text stream?
There are probably obvious answers. It's just not clear to me.
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability.
The devil is in the details, and those are not clear to me. Can you explain exactly what you are trying to do, and give us some examples of exactly the kind of output we have to parse? What are the "special characters" that are involved, and what constitutes a line/field break in the stream? What kind of things does the bash script need to do with the input it gets?
Bash variables can store any character except null (so it can be used as a field delimiter, but is otherwise mostly impossible to deal with). Other than that, it's really just a trick of parsing the input. Assuming the output of the perl script is piped directly into the bash script, then it's just a matter of setting up the read command properly.
As for the second question, I'm not sure I understand your description there either, or what the posted script has to do with it. Are the "options" part of the same perl data stream? If so, then they must be parsed out of it as they are received. If not, then you may be able to just directly hand them to it on the command line. Or perhaps a separate file descriptor or fifo could be used.
BTW, be aware that "#!/bin/sh" runs scripts in posix-compliant mode, and most shell-specific features become either illegal or undefined. To get the full compliment of features, you have to specify the exact shell to use, "#!/bin/bash".
It the processes are fully independent, then there are Interprocess Communications (IPC) mechanisms to allow process to exchange data. A very good primer on this subject is Beej's Guide to IPC. It sounds like you are trying to use e-mail to exchange data between processes, and I guess that could work, although I think it would be considered a bit clumsy.
Thanks for the feedback.
The string of text is an entire email, so there are line feeds and all manner of characters inside the email.
I think I'll just write the email to file and be done.
|All times are GMT -5. The time now is 02:34 AM.|