I'm running Perl 5.24.1 x86 on a Windows 10 (Edit) Server 2012 R2 system. My question is why are there no errors when I open a filename that contains a colon ( ':' ) character? What happens is the open works and printing to the filehandle seems to work but the file that is created has a truncated name and no output is actually put into that file. The filename is truncated at the colon character.

The reason I'm asking is that before this I trusted the open to tell me if there was a problem with creating an output file. I was trying to test my logic in a larger program and put ':' in the filename to trigger an open error and it did not appear. The program silently failed with a garbled filename for the logfile.

Testcase number 8 in this program shows the problem. All the other tests either work or produce a file open error.

use warnings; use strict; my $count = 1; my @test_characters = qw( * . " / \ [ ] : ; | ); push @test_characters, ' '; push @test_characters, ','; foreach my $char (@test_characters){ print "char = \'$char\'\n"; my $logfile = $0; $logfile =~ s/\.pl$/_$count-$char---\.log/; $count++; print "logfile = >$logfile<\n"; if(not open my $fh_log, ">", $logfile) { print "Error *** Couldn't open logfile for output: $logfile - +$! : $^E ---\n",'-'x79,"\n"; next; } else { print "-- Opened logfile for output: $logfile ---\n"; if( not print $fh_log "-- Opened logfile for output: $logfile +---\n",'-'x79,"\n" ){ print "Couldn't print to file handle.$!--\n"; } print '-'x79,"\n"; } }

This is what is printed to the display:

char = '*' logfile = >testlog_1-*---.log< Error *** Couldn't open logfile for output: testlog_1-*---.log - Invalid argument : The filename, directory name, or volume label syntax is incorrect -- +- ---------------------------------------------------------------------- +--------- char = '.' logfile = >testlog_2-.---.log< -- Opened logfile for output: testlog_2-.---.log --- ---------------------------------------------------------------------- +--------- char = '"' logfile = >testlog_3-"---.log< Error *** Couldn't open logfile for output: testlog_3-"---.log - Invalid argument : The filename, directory name, or volume label syntax is incorrect -- +- ---------------------------------------------------------------------- +--------- char = '/' logfile = >testlog_4-/---.log< Error *** Couldn't open logfile for output: testlog_4-/---.log - No such file or directory : The system cannot find the path specified --- ---------------------------------------------------------------------- +--------- char = '\' logfile = >testlog_5-\---.log< Error *** Couldn't open logfile for output: testlog_5-\---.log - No such file or directory : The system cannot find the path specified --- ---------------------------------------------------------------------- +--------- char = '[' logfile = >testlog_6-[---.log< -- Opened logfile for output: testlog_6-[---.log --- ---------------------------------------------------------------------- +--------- char = ']' logfile = >testlog_7-]---.log< -- Opened logfile for output: testlog_7-]---.log --- ---------------------------------------------------------------------- +--------- char = ':' logfile = >testlog_8-:---.log< -- Opened logfile for output: testlog_8-:---.log --- ---------------------------------------------------------------------- +--------- char = ';' logfile = >testlog_9-;---.log< -- Opened logfile for output: testlog_9-;---.log --- ---------------------------------------------------------------------- +--------- char = '|' logfile = >testlog_10-|---.log< Error *** Couldn't open logfile for output: testlog_10-|---.log - Invalid argument : The filename, directory name, or volume label syntax is incorrect -- +- ---------------------------------------------------------------------- +--------- char = ' ' logfile = >testlog_11- ---.log< -- Opened logfile for output: testlog_11- ---.log --- ---------------------------------------------------------------------- +--------- char = ',' logfile = >testlog_12-,---.log< -- Opened logfile for output: testlog_12-,---.log --- ---------------------------------------------------------------------- +---------

Here is the contents of the folder that shows the truncated filename 'testlog_8-'

Volume in drive D is APPS Volume Serial Number is XXX Directory of D:\scripts\clear_dmp_files\test 10/09/2019 03:28 PM <DIR> . 10/09/2019 03:28 PM <DIR> .. 10/09/2019 03:28 PM 0 testdir.txt 10/09/2019 03:01 PM 833 testlog.pl 10/09/2019 03:27 PM 136 testlog_11- ---.log 10/09/2019 03:27 PM 136 testlog_12-,---.log 10/09/2019 03:27 PM 135 testlog_2-.---.log 10/09/2019 03:27 PM 135 testlog_6-[---.log 10/09/2019 03:27 PM 135 testlog_7-]---.log 10/09/2019 03:27 PM 0 testlog_8- 10/09/2019 03:27 PM 135 testlog_9-;---.log 10/09/2019 03:27 PM 2,629 testlog_out.txt 10 File(s) 4,274 bytes 2 Dir(s) 129,251,168,256 bytes free

In reply to Why are there no errors when opening a filename that contains colons on Win10 by Lotus1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.