Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I might be wrong, but using "exec" directly in CGI script is not very good idea. The "exec" simply replaces current binary with new binary, it does not terminate the process, so the Web server shall wait for this new binary to finish its work, and that might be undesirable.

The appropriate way would be to do fork then exit the parent and do exec in the child. Ideally, the child should also call POSIX::setsid, to detach itself away from Web server, otherwise it could be killed by the server.

Forking also makes possible to pass your password over the pipe. Something like the following could do the trick

my $chld = fork(); # I wan't the CGI to end quickly die "Can't fork: $!\n" if(!definded $chld); exit(0) if $chld; # CGI ends here POSIX::setsid(); # start new session $chld = open(CHLD, "|-"); # this does another fork internally die "Can't fork: $!\n" if(!definded $chld); if($chld == 0) { # this does the same as ">/dev/null 2>&1" in shell close(STDOUT); open(STDOUT, ">/dev/null"); close(STDERR); open(STDERR, ">&STDOUT"); # avoid parsing of the arguments by shell, especially if $Trigger_ +Job # or $Captured_User_Name contain some dangerous stuff exec './processor.pl', '-j', $Trigger_Job, '-u', $Captured_User_Na +me; } select(CHLD); # make CHLD my default output $| = 1; # enable autoflushing print $Captured_Password; # output captured password close(CHLD); # wait for child to finish it's work

The code above is not tested. Read more about processes groups and sessions to understand why the switch of session might be good.


In reply to Re: exec, echo and pipe by andal
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-03-28 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found