Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

confused path

by skyworld_chen (Acolyte)
on Oct 09, 2012 at 08:23 UTC ( #997949=perlquestion: print w/ replies, xml ) Need Help??
skyworld_chen has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have two programs with the same name, suppose its name is $prog1 and one is under diretory A and the other is under directory B. I just use FindBin and other modules provided by internal groups to find the path with B, then I do this: system("which $prog1"), it shows B/prog1, but if I do this: exec("$prog1"), I found the code A/prog1 is running. I was confused here. Can anybody help me? Thanks very much.

Comment on confused path
Re: confused path
by parv (Priest) on Oct 09, 2012 at 08:30 UTC
    Does A directory come before B in $PATH (or equivalent environment setting)? In any case, best to use is an absolute path.
Re: confused path
by choroba (Abbot) on Oct 09, 2012 at 08:32 UTC
    Can you show some code that demonstrates the issue?
    FindBin is not related to where system searches for executable files.
    Does system $prog1; run the same programme as exec $prog1;?
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      In what case would $prog1 be different if one instance is run by system() and other by exec()?
        I cannot imagine. But I cannot imagine how it were possible for which and exec, either.
        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      hi,

      thanks for reply. Let me explain what happened in detail: I need to transfer a simulation package from one internal network to another internal network in company. Though both networks use linux, there are some differences between them, such as tools setting etc.

      here is a piece of code from one script (I did some substitution to make things simple):

      (1) use FindBin; (2) use lib $FindBin::Bin; (3) use dbPrjPath; ## company internal package (4) my $dir = dbPrjPath::prjPath(); #find project path (5) my $prog = $FindBin::Script; (6) exec("$prog @ARGV");

      above is the code. suppose code above is prog1. In line (4) a new project path is got. In this new project path there is a same script named prog1. The total code will get new project path and run the script in that path with the same script name "prog1" as line (6) indicates, i.e, runs B/prog1. This works well in original system, but in the other system, code in line (6) always runs A/prog1 so it is a infinite loop, which is a strange thing to me.

      In order to trace it, I insert a code as this between line (5) and (6) as (5.5) system("which $prog") and it shows B/prog1. I then inserted some debug info to make sure exec("$prog") runs itself. This confused me. so What happened? I confused...

        Could you reformat your post so that (long) code snippets do not mix with rest of the text? As it is, it is hard to make sense (of code). In case you missed the formatting tips mentioned before the textarea ...

        Use: <p> text here (a paragraph) </p> and: <code> code here </code> to format your post; it's "PerlMonks-approved HTML":

        Please post the values of $dir & $prog. Given those values, tell us where the command to be executed lives.

        (Nonetheless I will venture into mind reading) By the clue of $Script - basename of script ..., try executing the command with path prefixed as in ...

        ... $prog = join '/' , $dir , $prog; exec( $prog , ... );

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-09-19 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (135 votes), past polls