I have a perl CGI script that grabs a bunch of variables from a user before executing another perl script with those variables. This execution is forked and backgrounded so that the browser doesn't hang waiting for the script to finish. The exit status of ./processor.pl doesn't matter to the browser user as it writes its output to a database, so I want to run it and detach from it immediately.

The following two are how the CGI script executes the job processor.

This works:

exec "./processor.pl -j $Trigger_Job -u $Captured_User_Name -P $Captured_Password > /dev/null 2>&1 &";

This does not:

exec "echo $Captured_Password | ./processor.pl -j $Trigger_Job -u $Captured_User_Name > /dev/null 2>&1 &";

The problem is that if I use the first example, the user's password shows up in ps or top as it's passed as a parameter which is why I'm trying to echo it instead.

Here's how the ./processor.pl is capturing the input (for the echo):

use Term::ReadKey; ReadMode 4; $User_Password = <STDIN>; ReadMode 0;

If I run echo bla | ./processor.pl -j 12 -u blabla in a terminal, it works, so I know that the echo'd password is being caught correctly in processor.pl. So my suspicion is with exec not handling the pipe correctly or something similar. Or perhaps a TTY issue - but I don't really know.

Why doesn't the echo work as I expect it to (like in bash), and how should I actually handle this password passing?

Thanks,
Ben


In reply to exec, echo and pipe by Chipwiz_Ben

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.