gitarwmn has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to read a list of files from a text file, slap it into an array and loop through the array calling a cmd to get the files from Visual Source Safe (this is in Windows).

The following doesn't seem to be working and I can't figure out why...

open(HANDLE, "|cmd ss get $/Tate_SP2/$dir/$fname -Ybarbarat,12 +345|" || die "Couldn't run process:$!" );
Anyone have any suggestions?
Here is the rest of the code...
#!c:/perl/bin/Perl.exe use strict; use warnings; my @filesaffected; my $builddir = "C:\\Source\\Tate_8.4\\Click2Coach"; my $dir; my $fname; my $tatedir = "C:\\Source\\Tate_8.4"; main(); sub main{ #get files from vss my $filepath = "C:\\Source\\files.log"; open (IN, $filepath) || die "Can't open $filepath:$!"; while ( my $line = <IN> ) { chomp $line; next if ($line =~ /^\s*$/ or # blank lines $line =~ /^\s*#/); # comments push(@filesaffected, $line); } close IN; for (@filesaffected){ ($dir, $fname)= $_ =~ /^(.*?)[\\\/]([^\\\/]+)$/; $dir =~ s{\\}{/}g; open(HANDLE, "|cmd ss get $/Tate_SP2/$dir/$fname -Ybarbarat,12 +345|" || die "Couldn't run process:$!" ); close HANDLE; } }

Replies are listed 'Best First'.
Re: open handle
by bart (Canon) on Dec 06, 2006 at 20:35 UTC
    open(HANDLE, "|cmd ss get $/Tate_SP2/$dir/$fname -Ybarbarat,12345|" || die "Couldn't run process:$!" );
    You can't open an external program with pipes for both reading and writing this way. Look at IPC::Open2 for a way that does work.
      Thanks, I'll look into these other things.
      In the mean time I tried this and it worked. I'm calling a batch script to do the Source Safe get.
      system "C:\\Source\\Tate_8.4\\Click2Coach\\vss.cmd $dir $fname";

      Now what I'm doing is trying to have a cgi script call the batch script but it doesn't work. Anyone know why?

Re: open handle
by Joost (Canon) on Dec 06, 2006 at 20:34 UTC
Re: open handle
by Crackers2 (Parson) on Dec 06, 2006 at 21:51 UTC

    In addition to the two-way pipe proble, I think your die is in the wrong place too. You want to die if the open failed, so it should be outside the parentheses.

    open(HANDLE, "|cmd ss get $/Tate_SP2/$dir/$fname -Ybarbarat,12345|" ) +|| die "Couldn't run pro +cess:$!";

    instead of

    open(HANDLE, "|cmd ss get $/Tate_SP2/$dir/$fname -Ybarbarat,12345|" || + die "Couldn't run pro +cess:$!" );

      Thanks for the corrections, I made many mistakes but it seems to be working now.
      Now is it possible to get this to work from a cgi script? I've tried it as a perl script and it works but when I try it from a browser as a cgi script it times out.