using 'system' and i/o redirection 
Author Message
 using 'system' and i/o redirection

On Win 2000 with perl 5.005_03 from ActiveState, i'm getting output
from a program by using ">" then reading the file, but this seems to
leave the file locked so I can't delete it.  What am i doing wrong?

E.g.

        $Command = "p4 fstat $filename | grep \"haveRev\"  >> temp.filerev" ;
        $sysretcode = system( $Command );
        open TEMPFILE, "temp.filerev" || die "Error opening file
'temp.filerev'";
        while(<TEMPFILE>)
        {
                $inputline = $_;
                ($junk, $haverev, $P4revno) = split(/\s+/, $inputline);  
                if ($haverev != "haveRev") {
                        die "cannot parse perforce rev number";
                }
        }
        $Command = "del temp.filerev" ;
        $sysretcode = system( $Command );

The last "system" returns zero from Windows but also gets:
   D:\proj\dni\src\instmsi\alan\temp.filerev
   The process cannot access the file because it is being used by
another process.

tia
alan



Sat, 24 Jul 2004 06:06:12 GMT  
 using 'system' and i/o redirection

Quote:
> On Win 2000 with perl 5.005_03 from ActiveState, i'm getting output
> from a program by using ">" then reading the file, but this seems to
> leave the file locked so I can't delete it.  What am i doing wrong?

You want the output from the program, not it's return status, right?
They why are you using 'system()' instead of backticks?

perldoc -f system:
        [...] This is
            *not* what you want to use to capture the output from a command,
            for that you should use merely backticks or "qx//", as described
            in the section on "`STRING`" in the perlop manpage. [...]

jue



Sat, 24 Jul 2004 06:20:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. system( 'dialog', ...) and redirection

2. discarding stdout when using 'system(@args)'

3. Using Image::Size.pm on system where I can't install modules using make

4. Redirection but no 'Back'

5. using here document in perl's system command

6. Strange behavior using Perl's system() function to query SQL Server with osql

7. newbie: using 'exec' and 'system'

8. Looking for 'statfs' system call interface

9. Capturing return from 'system' call

10. stdout from 'system'?

11. 'system (...)' with arguments

12. Clarification on 'system' command

 

 
Powered by phpBB® Forum Software