exec, echo and pipeby Chipwiz_Ben (Initiate)
|on Apr 01, 2016 at 02:47 UTC||Need Help??|
Chipwiz_Ben has asked for the wisdom of the Perl Monks concerning the following question:
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.
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):
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?