Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Can I use Mojo::IOLoop::Subprocess for a non-blocking process?

by talexb (Canon)
on Mar 29, 2019 at 15:33 UTC ( #1231875=note: print w/replies, xml ) Need Help??


in reply to Re: Can I use Mojo::IOLoop::Subprocess for a non-blocking process?
in thread Can I use Mojo::IOLoop::Subprocess for a non-blocking process?

Yup .. that's what I ended up doing.

my $cmd = "cd /home/foo/$row->{'dir'} && " . "./$row->{'name'}.pl >some.out 2>some.err &"; my $result = system ( $cmd );

And it works fine. Thanks for following up.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

  • Comment on Re^2: Can I use Mojo::IOLoop::Subprocess for a non-blocking process?
  • Download Code

Replies are listed 'Best First'.
Re^3: Can I use Mojo::IOLoop::Subprocess for a non-blocking process?
by afoken (Canon) on Mar 30, 2019 at 15:56 UTC
    my $cmd = "cd /home/foo/$row->{'dir'} && " . "./$row->{'name'}.pl >some.out 2>some.err &"; my $result = system ( $cmd );

    Potential shell injection vulnerability ($row->{'dir'} and $row->{'name'}). Consider using fork and exec manually.

    Rough sketch:

    1. my $pid=fork() // die
    2. In the main program ($pid != 0), call waitpid($pid) at some point to wait for the end of the program you have forked before. Perhaps in a SiGCHLD handler.
    3. In the child process ($pid == 0), do the following:
    4. chdir("/home/foo/$row->{'dir'}") or die
    5. open STDOUT,'>','some.out' or die
    6. open STDERR,'>','some.err' or die
    7. exec("$row->{'name'}.pl") or die

    Related: The problem of "the" default shell

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      In my quest to make my self-contained example as brief as possible, I neglected to point out that the $row variable comes from an array under source control, and not from user input. All the user can do is press a button. (Yes, technically they could edit the page and make up their own button value, but if that value isn't in the array, nothing is executed.)

      An earlier version of my code did use fork/exec, but it didn't work as expected under Mojolicious (Mojo waited for the child to finish), so I moved on to other approaches.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1231875]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2019-07-17 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?