Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1103215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:18:30+00:00 2026-05-17T01:18:30+00:00

I’m using Thread::Pool::Simple to create a few working threads. Each working thread does some

  • 0

I’m using Thread::Pool::Simple to create a few working threads. Each working thread does some stuff, including a call to chdir followed by an execution of an external Perl script (from the jbrowse genome browser, if it matters). I use capturex to call the external script and die on its failure.

I discovered that when I use more then one thread, things start to be messy. after some research. it seems that the current directory of some threads is not the correct one.

Perhaps chdir propagates between threads (i.e. isn’t thread-safe)?
Or perhaps it’s something with capturex?

So, how can I safely set the working directory for each thread?

** UPDATE **

Following the suggestions to change dir while executing, I’d like to ask how exactly should I pass these two commands to capturex?

currently I have:

my @args = ( "bin/flatfile-to-json.pl", "--gff=$gff_file", "--tracklabel=$track_label", "--key=$key", @optional_args );
capturex( [0], @args );

How do I add another command to @args?
Will capturex continue die on errors of any of the commands?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:18:31+00:00Added an answer on May 17, 2026 at 1:18 am

    I think that you can solve your “how do I chdir in the child before running the command” problem pretty easily by abandoning IPC::System::Simple as not the right tool for the job.

    Instead of doing

    my $output = capturex($cmd, @args);
    

    do something like:

    use autodie qw(open close);
    my $pid = open my $fh, '-|';
    unless ($pid) { # this is the child
      chdir($wherever);
      exec($cmd, @args) or exit 255;
    }
    my $output = do { local $/; <$fh> };
    # If child exited with error or couldn't be run, the exception will
    # be raised here (via autodie; feel free to replace it with 
    # your own handling)
    close ($fh);
    

    If you were getting a list of lines instead of scalar output from capturex, the only thing that needs to change is the second-to-last line (to my @output = <$fh>;).

    More info on forking-open is in perldoc perlipc.

    The good thing about this in preference to capture("chdir wherever ; $cmd @args") is that it doesn’t give the shell a chance to do bad things to your @args.

    Updated code (doesn’t capture output)

    my $pid = fork;
    die "Couldn't fork: $!" unless defined $pid;
    unless ($pid) { # this is the child
      chdir($wherever);
      open STDOUT, ">/dev/null"; # optional: silence subprocess output
      open STDERR, ">/dev/null"; # even more optional
      exec($cmd, @args) or exit 255;
    }
    wait;
    die "Child error $?" if $?;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.