Confusion with quoted strings in system() arguments
> Sent: Friday, August 11, 2000 07:50
> Subject: Confusion with quoted strings in system() arguments
> Why are these two system calls not the same?
Those are not 'system calls'; they are calls to the system() function.
A 'system call' requests a service from the operating system, for
example opening or printing to a file.
> The first one works but the second one does not. I thought
> they would be syntactically the same, but the second one
> fails with "The filename, directory name, or volume label
> syntax is incorrect."
> (ActiveState Perl 5.6.0 on Windows NT)
> $Prog = "C:\\WinNt\\Notepad.exe";
> $File = "C:\\My Documents\\Temp\\sometext.xxx";
When in doubt, print it out! Replace 'system' by 'print' to see what
the argument string is.
Look, ma, no double-quotes!
> # system ( "\"$Prog\"", "\"$File\"" ) ;
But that one does have double-quotes explicitly.
There are several ways to fix this. Here is a simple one:
$Prog = '"C:\WinNt\Notepad.exe"';
$File = '"C:\My Documents\Temp\sometext.xxx"';