Pmand
Pmand

Reputation: 7

Execute a perl script which doesnt have the .pl extension from another perl script which have the .pl extension

How to execute a perl script with a file named "first" (no extension) from another perl script called second.pl on Windows?

File contents of first:

#!/usr/bin/perl5.8.4 -w
>> Some code

File contents of second.pl:

#!/usr/bin/perl
use strict;
use warnings;

system "first";

So my problem is when I execute the file "first" from the Windows command line, it works

but if I try to run it from my file "second.pl", using system "first"; it fails with the below error:

can't exec "first" : Not a directory at "second.pl" at line 6

Upvotes: 0

Views: 198

Answers (1)

JGNI
JGNI

Reputation: 4013

Windows uses the file extension to work out how to run a file. As you have no extension the OS is thinking you are trying to open a directory.

You can fix this by changing system "first"; to

system $^X, "first"

This will get Windows to run the current Perl interpreter again, passing your script name as the first parameter, which gets Perl to run it.

Upvotes: 1

Related Questions