Basic problem running perl script in windows.

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
I've never run a perl script before so I'm probably missing something.

Installed ActivePerl. Windows 7.

I've got a script called pictures.pl. It takes a bunch of jpgs in the same directory, reads their filenames, and generates links to these images based off of an html template page.

So the html page that we're trying to create is a photo gallery with a grid of thumbnails. The script reads the filenames and then creates img src links into this html page so that the thumbnails will show.

I double click on the pictures.pl and a command line window briefly pops up and disappears. Nothing happens. No new files are created. The file is being opened with Perl Command Line Interface.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Go to Start -> Run -> cmd, then run the script from there. The command line window will not disappear, so you'll be able to see what went wrong.
 

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
Ok, I ran it and it's giving me an error, but I'm confused why it's erroring out here. (Error: Syntax: pic_pages.pl DIRECTORY CITY) Looked in the code and the error is contained in this piece of code, which is almost first section of code you encounter.

if (($ARGV[0] ne "") && ($ARGV[1] ne "")){
$home_picture = $home_title = $directory = $ARGV[0];
$keyword_city = $city = $ARGV[1];
}else{
die "Syntax: pic_pages.pl DIRECTORY CITY\n";
}

So it's checking to see if argument variables 0 and 1 in the array ARGV are empty. Looks like I'm missing the pic_pages.pl file? Cuz I don't have that and the error's referring to it.
 

Daverino

Platinum Member
Mar 15, 2007
2,004
1
0
I see your first mistake:

use strict;
use warnings;

is missing from the top of your script. . .
 

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
Originally posted by: Daverino
I see your first mistake:

use strict;
use warnings;

is missing from the top of your script. . .

It's actually not my script, it's my client's. He uses this script to automatically generate the 30 or so html pages for his photo gallery. I'm just trying to run it. And I've never run nor seen perl before.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,633
4,562
75
It's a reference to the script that's running. He probably should have said:

die "Syntax: $0 DIRECTORY CITY\n";

But that's neither here nor there. In any case, you need to run the script on the command line (or from start->run). So if the script is named "pic_pages.pl", make sure perl.exe is in your PATH environment variable, and then run:

perl pic_pages.pl DIRECTORY CITY

Either it will error somewhere else, or it will show you what it does with DIRECTORY and CITY, so you know what to put there.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Yea, as Ken says, the script isn't smart enough to figure out your current directory and process that. You have to specifically tell it which directory to process via the command line.
 

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
Ohhhh... I thought all this time that I just had to place it in the directory in question and it would just take it from there. I'm not sure what DIRECTORY CITY is.

so i go to run - cmd and do:

perl D:\pictures\123 apple st\pic_pages.pl D:\pictures\123 apple st ?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Well, if you first cd to that directory you can just use "." for the directory name since that's always the current directory.
 

Aluvus

Platinum Member
Apr 27, 2006
2,913
1
0
Originally posted by: fuzzybabybunny
Ohhhh... I thought all this time that I just had to place it in the directory in question and it would just take it from there. I'm not sure what DIRECTORY CITY is.

so i go to run - cmd and do:

perl D:\pictures\123 apple st\pic_pages.pl D:\pictures\123 apple st ?

Having little experience with Perl on Windows...

DIRECTORY should be the directory you want to process. CITY is presumably the name of the city (maybe used for a page title or something?). So:

perl pictures.pl C:\your\directory Atlanta

If your directory or city name contains a space, you will (presumably) need to put single-quotes 'like this' to keep it from being broken up. You should also be able to use relative directories (rather than starting from the root of C:\ as I did above).

You should also be aware that if this script was not originally developed on Windows, and the developer didn't know what he was doing, random things may explode when it is run on Windows.
 

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
D:\Temp Photo Work\20090715 300Monroe\FinishedImages>perl pictures.pl D:\Temp_Photo_Work\20090715_300Monroe\FinishedImages Mountain_View

directory: D:\Temp_Photo_Work\20090715_300Monroe\FinishedImages
home title: 20090715 D:\Temp Photo Work\, Unit 300Monroe, Mountain_View
keyword_city: mountain_view

Unable to open Directory: D:\Temp_Photo_Work\20090715_300Monroe\FinishedImages

I tried playing around with it some more just now and still can't get anything meaningful.

Why is it unable to open the directory? There's no typo...

The single quotes did not work to keep directories and names with spaces from being broken up. Double quotes don't work either. So I used underscores. The guy uses WinXP.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Have you tried running it from the directory with the images like I suggested earlier?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,633
4,562
75
In that directory, try this (make the whole line look like this):

D:\Temp Photo Work\20090715 300Monroe\FinishedImages>perl pictures.pl . Mountain_View
(You only type the "perl pictures.pl . Mountain_View" part.)

or likewise

D:\Temp Photo Work\20090715 300Monroe\FinishedImages>perl pictures.pl . "Mountain View"

. refers to the current directory. (.. refers to the parent, if you're intetersted.)
 

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
Originally posted by: Nothinman
Have you tried running it from the directory with the images like I suggested earlier?

Yeah, I was running it from the directory.

Originally posted by: Ken g6
In that directory, try this (make the whole line look like this):

D:\Temp Photo Work\20090715 300Monroe\FinishedImages>perl pictures.pl . Mountain_View
(You only type the "perl pictures.pl . Mountain_View" part.)

or likewise

D:\Temp Photo Work\20090715 300Monroe\FinishedImages>perl pictures.pl . "Mountain View"

. refers to the current directory. (.. refers to the parent, if you're intetersted.)

This worked. Man, this script was a pain in the ass to run. The guy didn't even give me all the necessary files - had to go poking around on his website hoping that he'd saved it in some directory and the script was outdated and had to be edited a bit.

The error message of die "Syntax: pic_pages.pl DIRECTORY CITY\n"; was throwing me for a loop because the actual script itself is called pictures.pl and I was wondering what pic_pages.pl was referring to, so his comments and error messages were outdated as well.

So from now on, every time I run the script, I have to cmd and type in the entire directory address? Is there some easier way that I can just double click on the script and it'll run?