-3

I am working in Cygwin on a Windows 7 machine. I linked Cygwin perl to windows strawberry perl.

10:13 PM Thu Jan 14$ ls -ltr /usr/bin/perl
lrwxrwxrwx 1 casper None 40 Nov 29 21:40 /usr/bin/perl -> /cygdrive/c/strawberry/perl/bin/perl.exe

I have a script that accepts a command line argument. When I put in the directory path, it cannot read the file in.

casperw@W01B6XLV /cygdrive/c/casper/DEV$ ./parseCMTA /tmp/example.txt
Error opening /tmp/example.txt - No such file or directory

I copy it to the same path that the script is in and it works just fine:

casperw@W01B6XLV /cygdrive/c/casper/DEV$ cp /tmp/example.txt .
casperw@W01B6XLV /cygdrive/c/casper/DEV$ ./parseCMTA example.txt
Short name – ORANGEJulius
GL- 7512522  ADP- 20692677
GL- 7512524    ADP- 21692677
CMTA TO MS 050
casperw@W01B6XLV /cygdrive/c/casper/DEV$ cat parseCMTA
#!/usr/bin/perl
use strict ;
use warnings ;
my $file_grab = $ARGV[0] ;
open my $CMTA_file , '<' , $file_grab or die "Error opening $file_grab - $!\n";
while (<$CMTA_file>) {
    print $_ ;
}

How come the command line array @ARGV will not process the absolute path of the file location, however it will process the file when it is in the same directory. What is going on with the absolute path and the @ARGV array?

capser
  • 2,442
  • 5
  • 42
  • 74
  • 3
    The program you posted doesn't even compile, much less provide the output you claim it does. – ikegami Jan 14 '16 at 05:46
  • 2
    You seem to be using Cygwin. I am not familiar with it, but my understanding is that it does some arcane stuff with absolute paths, nominally to shield you from the Dark Force of the underlying horror, but ultimately just giving it a different guise. – tripleee Jan 14 '16 at 10:51
  • 1
    To follow up on tripleee, try `./parseCMTA "$(cygpath -w /tmp/charles)"` – glenn jackman Jan 14 '16 at 11:38
  • @glenn jackman, That's what you would do if `./parseCMTA` was Windows program, but he said it was `/usr/bin/perl` which would be a cygwin program. – ikegami Jan 14 '16 at 14:32
  • @capser, have you tried using the [perl debugger](http://perldoc.perl.org/perldebug.html) to see what's in $ARGV[0]? `/usr/bin/perl -d ./parseCMTA /tmp/charles` – glenn jackman Jan 14 '16 at 14:37

1 Answers1

2

Strawberry Perl has not been compiled with Cygwin subsequently /tmp is actually C:\tmp instead of a space within Cygwin. So, assume any path you give to Strawberry Perl is a normal Windows path (I believe / and \ are the same in Strawberry Perl paths). If you know the location in Windows of Cygwin's /tmp, you can use that.

kjpires
  • 730
  • 4
  • 14
  • I added the perl to strawberry link AFTER I posted the question. Glenn Jackman suspected this without the information. GOOD Debugging Glenn !!!!!!! – capser Jan 16 '16 at 11:58