Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

What does chdir ?

by pcouderc (Monk)
on Feb 16, 2017 at 07:26 UTC ( [id://1182122]=perlquestion: print w/replies, xml ) Need Help??

pcouderc has asked for the wisdom of the Perl Monks concerning the following question:

This script fails :
#!/usr/bin/perl # # chdir 'core/efl'; `./autogen.sh`;
But if I key :
cd core/efl ./autogen.sh
my configuration is ok. What do I miss ? What is the difference ?

Update: added . in front of /autogen.sh in second code snippet

Replies are listed 'Best First'.
Re: What does chdir ?
by haukex (Archbishop) on Feb 16, 2017 at 09:08 UTC

    Hi pcouderc,

    How does the program "fail"? Is it just that you're not seeing output? The difference between the two samples you showed is that backticks capture the output of the program, which you are not doing anything with. So, probably system is better (I wrote at length about the two, their problems, and possible alternatives here), also, you should add some error checking. The following works for me:

    #!/usr/bin/env perl use warnings; use strict; chdir 'core/efl' or die "failed to chdir: $!"; system('./autogen.sh')==0 or die "system failed, \$?=$?";

    Hope this helps,
    -- Hauke D

      Thank you, you are right. Using :
      print `./autogen.sh';
      shows the correct output. So you are right : it does not fail !!
      And I shall use error checkong as you indicate. Thank you again.
        Note that once Perl exits, you will no longer be in 'core/efl'. Perl's chdir does not move the directory of the parent that started Perl. You can eliminate the chdir and combine the chdir path into the system command's path to autogen.sh with a very similar result.
Re: What does chdir ?
by Anonymous Monk on Feb 16, 2017 at 07:38 UTC

    What do I miss ? What is the difference ?

    The difference is the two paths aren't identical

    Its like when you try to use your key on my front door, it doesn't work, cause the path is different

    Also use absolute paths , and do error checking, like

    use autodie qw/ chdir /; chdir ...;
      Sorry (I have corrected a missing point before the /), but I do not see the difference. So I am sorry I do not understand your answer.
      About absolute paths, in this case I would like to use relative paths if possible.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1182122]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found