Reputation: 5175
I found this piece of code in perl
system("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude");
However I don't understand how it is working. I mean system() is used to fire 'system' commands right ? So is this 'zip' command used here a 'system' command ? But I tried firing just the following on the command prompt;
zip $ZIP_DEBUG -r -9 itvlib.zip arg1 arg2
It didn't work ! it gave the following error:
'zip' is not recognized as an internal or external command,
operable program or batch file.
Well this shouldn't have happened, since the command seems to use 'zip' as a system command. So this makes the command 'zip' mysterious
Can you please help me to understand this command with all its parameters?
Upvotes: 2
Views: 2836
Reputation: 62109
system("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude");
is running a program named zip
(probably zip.exe
) somewhere on the path. $ZIP_DEBUG
, $include
, and $exclude
are Perl variables that are interpolated into the command line before the command is run.
If the system
call works in the Perl script, but zip -?
gives the 'zip' is not recognized as an internal or external command, operable program or batch file
error, then the PATH of the Perl script must be different than the PATH in your command prompt. Or, there might be a zip
command in the current directory when Perl executes the system
command. (In Windows, the current directory is an implicit member of your PATH.)
To see what the PATH is for the Perl script, you can add a print "$ENV{PATH}\n";
before the system command. To see what the PATH is in your command prompt, type PATH
.
Upvotes: 4
Reputation: 882296
It's probably not working since you're not replacing things like $ZIP_DEBUG
with their equivalent real values. Within Perl, they will be replaced with the values of the variables before being passed to the system
call.
If you print out those Perl variables (or even the entire command) before you execute that system
call, you'll find out those real values that you need to use. You can use the following transcript to guide you:
$ perl -e '
> $ZIP_DEBUG = "xyzzy";
> $include = "inc_files";
> $exclude = "exc_files";
> print "zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude";
> '
zip xyzzy -r -9 itvlib.zip inc_files exc_files
For details on how system
works, see here. For details on what zip
needs to function, you should just be able to run:
man zip
from a command line shell (assuming you're on Linux or its brethren). If, instead, you're on a different operating system (like Windows), you'll have to figure out how to get the zip options out. This may well be as simple as zip -?
of zip -h
but there's no guarantee that will work.
If it's the same as the Info-ZIP zip
under Linux (and it may be if you have the -9
and -r
options and your exclude
variable starts with -x
), then zip -h
will get you basic help and zip -h2
will give you a lot more.
Upvotes: 5
Reputation: 9121
Yes, zip
is a system command. The variables $ZIP_DEBUG
and such are perl variables that are interpolated to the command before launching zip
.
To debug what the actual call is, try adding:
print("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude\n");
See perldoc for details on system
.
Upvotes: 3