Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Kakesu
Nov 4, 2005

ETHICAL.

I have an incredibly annoying problem that is completely stumping myself and some other perl users at work, that I'm really hoping somebody can help with. I'm using ActivePerl in windows, and the script in question is designed to run a build process automatically. The script runs on two separate PCs, alternating back and forth so that there's a constant stream of new builds. None of this is really relevant to the problem, but I thought some background would be nice.

The problem is this: at one point in the script, the Windows "mkdir" command is called using a system() call. On ONE MACHINE ONLY, this fails, regardless of the location of the directory that is being created. The other machine executes the command just fine. The actual script creates a directory on another machine over the network, but I've tested it with local directories, and the same failure happens. Running the mkdir from a Windows command prompt works fine in both cases.

The line of code in question is this:
code:
system("mkdir \"\\\\machine-name\\shared_directory\\directory_to_create\"");
From my testing, it appears that the backslashes in the path aren't all escaping properly. The error that is thrown indicates that perl is trying to run the following command when this is run:
code:
mkdir "\\machine-name\\shared_directory\\directory_to_create"
The first backslashes escape as they're supposed to, but the ones later on in the path don't. Just for shits and giggles, I tried replacing those with single backslashes in the script, and got the following:
code:
mkdir "\\machine-nameshared_directory\directory_to_create"
The second set disappears completely, but the third displays the way that we originally wanted it to (even though it shouldn't).

We've tried re-installing Perl, using a different version of Perl, rechecking permissions, etc. Nothing seems to make any difference. Has anyone seen anything similar to this before, or have any ideas why a string that would be parsed normally on one machine, would be parsed completely differently on another machine running an identical Perl install?

Adbot
ADBOT LOVES YOU

Kakesu
Nov 4, 2005

ETHICAL.

Triple Tech posted:

For starters, don't make shell calls if there are CPAN modules available to do the same thing. There should definitely be an ActiveState-approved module that creates file paths...

Two, the system function accepts arrays! The first argument to the function is the command you want to run and subsequent arguments are arguments to the command, properly and automatically escaped by Perl.

So, you should try to write out your system call (which you shouldn't be using) like this:
code:
system('mkdir', $dirname);
And you can test if you have the correct number of slashes by just printing $dirname to STDOUT. That or just use forward slashes (no escaping necessary).

Thanks. Right after I posted that, we found another Perl user that explained that we could just use mkdir on its own, without a shell call, and that seems to be working.

Still no idea why it stopped working, though. The thing I forgot to mention in my original post is that this script has been running continuously for the past 3 months, but this is the first time it's failed like this. Very strange.

  • Locked thread