Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Execution of a script

by waytoperl (Beadle)
on Sep 26, 2014 at 15:55 UTC ( [id://1102153]=perlquestion: print w/replies, xml ) Need Help??

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

If filerun.pl executed from Dist_Folder, there is no error

C:\Users\Admin\Desktop\Dist_Folder\perl filerun.pl
#!/usr/bin/env perl -w use strict; use warnings; use Diagnostics; my $file = "InFile.csv"; { open( INFILE, "$file" ) or die("Can not open input file: $!"); close(INFILE); }

I'm trying to run filerun.pl in a Zombie folder and getting error message!!!

C:\Program Files\Zombie>perl C:\Users\Desktop\Dist_Folder\filerun.pl
Can not open input file: No such file or directory at ...line xyz

Dependency in Zombie folder make's me to run script from Zombie. Thanks for help!

Replies are listed 'Best First'.
Re: Execution of a script
by choroba (Cardinal) on Sep 26, 2014 at 16:01 UTC
    You need FindBin.
    use FindBin; my $file = $FindBin::Bin . '/InFile.csv'; open my $INFILE, '<', $file or die $!;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Still same error

      C:\Program Files\Zombie>perl C:\Users\Desktop\Dist_Folder\filerun.pl Can not open input file: No such file or directory at ...line xyz
Re: Execution of a script
by Anonymous Monk on Sep 26, 2014 at 16:02 UTC

    That depends on whether the file will always be located at C:\Users\Admin\Desktop\Dist_Folder\InFile.csv, or whether the file will always be located in the same directory as the script. In the first case, you can just specify the full filename, e.g. my $file = "C:\\Users\\Admin\\Desktop\\Dist_Folder\\InFile.csv";

    In the second case:

    use File::Spec; use FindBin; my $file = File::Spec->catfile($FindBin::Bin, "InFile.csv");

      Thank you! complete path to InFile.csv and File::Spec worked

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found